测试 – 角2 RC5后测试失败

前端之家收集整理的这篇文章主要介绍了测试 – 角2 RC5后测试失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用以下格式进行测试:
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 / tests可以获得可用的茉莉花进口.所以删除以下的导入

之前:

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';

参考路径应该是文件中的第一行,它应该指向茉莉花类型定义文件. (更新相对上,即../../到任何)要获取茉莉花类型的定义,请将以下行添加到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(...);
});
原文链接:https://www.f2er.com/angularjs/142644.html

猜你在找的Angularjs相关文章