[英]Error: No provider for Compiler! DI Exception Angular 2 Testing
The given unit test throws error when executed using npm test command. 使用npm test命令执行时,给定的单元测试会抛出错误。 It says there was a DI Exception with error message "Error: No provider for compiler!" 它说有一个DI异常,错误消息“错误:编译器没有提供者!”
import {TestComponentBuilder} from "@angular/compiler/testing";
import {
expect,
it,
describe,
async,
inject,
beforeEach,
beforeEachProviders
} from "@angular/core/testing";
import {provide} from '@angular/core';
import {TestService} from "../services/Test.service";
import {TestComponent} from "./Test.component";
describe('Component: TestComponent', () => {
let tcb;
beforeEachProviders(() => [
TestComponentBuilder,
TestComponent,
TestService
]);
beforeEach(inject([TestComponentBuilder], (testComponentBuilder) => {
tcb = testComponentBuilder;
}));
it('getTest', testGetTest => {
**tcb.createAsync(TestComponent)**
.then(fixture => {
let TestComponent = fixture.componentInstance;
TestComponent.selectedUserId = 3;
expect(TestComponent.selectedUserId).beEqual(3);
});
});
});
The error is thrown most probably on tcb.createAsync 该错误最有可能发生在tcb.createAsync上
Following dependencies were added to project 以下依赖项已添加到项目中
"jasmine-core": "~2.4.1",
"karma": "1.x || ^0.13.0",
"karma-chrome-launcher": "1.x || ~0.2.2",
"karma-firefox-launcher": "1.x || ~0.1.7",
"karma-cli": "*",
"karma-jasmine": "1.x || ^0.3.6",
"karma-spec-reporter": "0.0.13",
"browserify": "latest",
"karma-browserify": "latest"
I think you need 我想你需要
import {setBaseTestProviders} from '@angular/core/testing';
import {
TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS
} from '@angular/platform-browser-dynamic/testing';
setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
https://github.com/angular/angular/blob/master/CHANGELOG.md#200-rc0-2016-05-02 https://github.com/angular/angular/blob/master/CHANGELOG.md#200-rc0-2016-05-02
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.