Jasmine 中的 'should create' 测试用例是什么
What is 'should create' test case in Jasmine
我是 Angular 中使用 Jasmine 和 Karma 进行单元测试的新手。我是实习生。我正在浏览一个规格文件。我想知道在这种情况下 should create 是什么意思。 TimeselectorComponent 是我要测试的组件。我从学长那里拿了代码。代码是这样的:
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
import { TimeselectorComponent } from './timeselector.component';
...
describe('TimeselectorComponent', () => {
let fixture: ComponentFixture<TimeselectorComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...
],
providers: [...],
declarations: [TimeselectorComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TimeselectorComponent);
});
it('should create', () => {
expect(fixture.componentInstance).toBeTruthy();
});
// other test cases
});
还有其他测试用例,但现在我对 'should create' 案例感到好奇。我的理解是它正在尝试测试组件是否为 initialized/created。如果我错了,请纠正我。请告诉我更多有关上述代码的信息。也想了解 compileComponent()
方法。我检查了这个 link 但只能理解一点:
compileComponents() is asynchronous, we must use async()
我也在回答这个问题:
每个 it 块中的字符串是一个测试用例名称。第一个测试用例是 should create,你将它与描述中的字符串结合起来,即 TimeSelectorComponent,它变成 TimeSelectorComponent should create。此测试用例检查 TimeSelector 组件是否已初始化。您也可以根据您的方便或编写测试用例的方式更改此字符串。
Compilecomponents 是一种编译您在测试平台中提到的所有组件的方法。接受任务需要时间,这就是为什么它是异步的,这样你的主线程就不会被阻塞,如果你想这样做,你可以并行地做一些其他的设置。这就是为什么 async 关键字是强制性的,以便每个人都可以等待内部执行的所有异步任务完成。因为如果我们的组件没有准备好,测试用例将失败。
我是 Angular 中使用 Jasmine 和 Karma 进行单元测试的新手。我是实习生。我正在浏览一个规格文件。我想知道在这种情况下 should create 是什么意思。 TimeselectorComponent 是我要测试的组件。我从学长那里拿了代码。代码是这样的:
import { TestBed, ComponentFixture, async } from '@angular/core/testing';
import { TimeselectorComponent } from './timeselector.component';
...
describe('TimeselectorComponent', () => {
let fixture: ComponentFixture<TimeselectorComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
...
],
providers: [...],
declarations: [TimeselectorComponent],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TimeselectorComponent);
});
it('should create', () => {
expect(fixture.componentInstance).toBeTruthy();
});
// other test cases
});
还有其他测试用例,但现在我对 'should create' 案例感到好奇。我的理解是它正在尝试测试组件是否为 initialized/created。如果我错了,请纠正我。请告诉我更多有关上述代码的信息。也想了解 compileComponent()
方法。我检查了这个 link 但只能理解一点:
compileComponents() is asynchronous, we must use async()
我也在回答这个问题:
每个 it 块中的字符串是一个测试用例名称。第一个测试用例是 should create,你将它与描述中的字符串结合起来,即 TimeSelectorComponent,它变成 TimeSelectorComponent should create。此测试用例检查 TimeSelector 组件是否已初始化。您也可以根据您的方便或编写测试用例的方式更改此字符串。
Compilecomponents 是一种编译您在测试平台中提到的所有组件的方法。接受任务需要时间,这就是为什么它是异步的,这样你的主线程就不会被阻塞,如果你想这样做,你可以并行地做一些其他的设置。这就是为什么 async 关键字是强制性的,以便每个人都可以等待内部执行的所有异步任务完成。因为如果我们的组件没有准备好,测试用例将失败。