Angular:在Jasmine中设置超时

时间:2017-05-22 11:23:35

标签: angular jasmine karma-runner

我正在使用jasmine 2.5和karma 1.4运行单元测试。 对于其中一些我收到超时错误:

Chrome 58.0.3029 (Windows 7 0.0.0) BeratungdetailsComponent should be in Testfall 2 Soring 29 FAILED
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.
    at ZoneDelegate.invokeTask (webpack:///~/zone.js/dist/zone.js:424:0 <- src/polyfills.ts:3072:31)
    at Zone.runTask (webpack:///~/zone.js/dist/zone.js:191:0 <- src/polyfills.ts:2839:47)
    at ZoneTask.invoke (webpack:///~/zone.js/dist/zone.js:486:0 <- src/polyfills.ts:3134:38)
    at timer (webpack:///~/zone.js/dist/zone.js:1512:0 <- src/polyfills.ts:4160:29)

所以我尝试了jasmin的overloade it-method,指定了这个测试的超时时间:

it('should be checkGespraechspartner is true when Name and Vorname is not set', () => {
  const formPerson = component.personComponent.personForm;
  const personVornameControl = formPerson.get('personVorname');
  const personNameControl = formPerson.get('personName');

  personVornameControl.setValue('');
  personNameControl.setValue('');
  expect(component.personComponent.checkGespraechspartner()).toEqual(true);   
}, 25000);

我还是暂停了。

所以我尝试在beforeEach-method中设置超时:

beforeEach(() => {
  jasmine.DEFAULT_TIMEOUT_INTERVAL = 25000;

这很好用。

我认为通过使用重载的it方法(将超时指定为第三个参数),jasmin将使用此值而不是default-timeout。

所以我在使用重载方法时有点困惑。

0 个答案:

没有答案