gpt4 book ai didi

testing - Angular 2 RC5 后测试失败

转载 作者:太空狗 更新时间:2023-10-29 17:02:35 24 4
gpt4 key购买 nike

我在测试中使用了以下格式:

export function main() {
describe('Angular2 component test', function() {
it('should initialize component',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
var template = '<specific-component-tag>';
return tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture) => {
expect(fixture.componentInstance.viewChild).toBeDefined();
fixture.detectChanges();
expect(fixture.componentInstance.viewChild.items.length).toBe(1);
// .... etc.
}).catch (reason => {
console.log(reason);
return Promise.reject(reason);
});
})));
});
}
这在 RC4 中工作正常。但是RC5突然来了,现在这段代码已经失效了。它抛出以下错误:

Module ".... @angular/core/testing" has no exported member 'it'.
Module ".... @angular/core/testing" has no exported member 'describe'.
Module ".... @angular/core/testing" has no exported member 'expect'.
Module ".... @angular/core/testing" has no exported member 'beforeEachProviders'.
Module ".... @angular/compiler/testing" has no exported member 'TestComponentBuilder'.
Module ".... @angular/compiler/testing" has no exported member 'ComponentFixture'.

请帮助我将此测试迁移到 angular2 RC5。

更新:我已经读过 RC5 release notes但我没有想到如何实现我的目标。

最佳答案

删除了通过@angular/core/testing 提供的 Jasmine 导入。因此,删除以下内容的导入

之前:

import {
beforeEach,
beforeEachProviders,
describe,
expect,
it,
inject,
} from '@angular/core/testing';

之后

/// <reference path="../../../typings/main/ambient/jasmine/index.d.ts" />
import {
inject, addProviders
} from '@angular/core/testing';

引用路径应该是文件中的第一行,它应该指向 jasmine 类型定义文件。 (更新相对向上。即 ../../到任何)要获得 jasmine 类型定义,请将以下行添加到 ambientDevDependencies。我的看起来像这样

{
"ambientDevDependencies": {
"angular-protractor": "registry:dt/angular-protractor#1.5.0+20160425143459",
"jasmine": "registry:dt/jasmine#2.2.0+20160412134438",
"selenium-webdriver": "registry:dt/selenium-webdriver#2.44.0+20160317120654"
},
"ambientDependencies": {
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654"
}
}

也改变

  beforeEachProviders(() => [InMemoryDataService]);

import { TestBed } from '@angular/core/testing';
...
describe('...', () => {
TestBed.configureTestingModule({
providers: [ InMemoryDataService ]
});
it(...);
});

关于testing - Angular 2 RC5 后测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38895087/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com