【发布时间】:2017-11-22 12:28:39
【问题描述】:
您好,我正在使用 Angular 和 TypeScript 开发应用程序。
以下是模板代码:
<input type="text" placeholder="Search Results" (input)="searchInput($event)">
我关于 searchInput 方法的打字稿代码是:
searchInput(event: Event & { target: HTMLInputElement}) {
const { value } = event.target;
this.value = value;
// calling other method to reset values
}
我想知道如何在我的 spec.ts 文件中编写输入测试用例。
describe('Component', () => {
let component: Component;
let fixture: ComponentFixture<Component>;
const event = Event; // Is this fine ?
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
AppModule
],
providers: [
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(Component);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('searchInput() ', () => {
// how to approach
});
});
请提供我将如何编写测试用例的方法。
【问题讨论】:
-
您可以查看@this repo 并检查规范文件,它非常基本但会帮助您我猜github.com/rahulrsingh09/AngularConcepts
-
感谢您的链接,但它并没有解决我的问题。
-
@Vaibhav 到目前为止你有什么尝试?
-
我还在寻找方法,我是新手。如果您有任何想法,请提出建议。
-
如果我是你,我唯一会做的就是
expect(component.value).toEqual(/*your value*/);(当然,之前打电话给component.searchInput())
标签: angular typescript testing jasmine karma-jasmine