angular2测试,使用setBaseTestProviders()时ViewUtils中的错误

时间:2016-06-10 09:04:05

标签: testing angular

使用方法' setBaseTestProviders(..)'时,控制台中会弹出错误。

我们正在使用angular-2.0.0-rc.1。

测试(test / areas-list.component.spec.ts)如下:

import {setBaseTestProviders} from "@angular/core/testing";
import {ADDITIONAL_TEST_BROWSER_PROVIDERS, TEST_BROWSER_STATIC_PLATFORM_PROVIDERS} from '@angular/platform-browser/testing/browser_static';
import {BROWSER_APP_DYNAMIC_PROVIDERS} from '@angular/platform-browser-dynamic';

setBaseTestProviders([
    BROWSER_APP_DYNAMIC_PROVIDERS,
    ADDITIONAL_TEST_BROWSER_PROVIDERS,
], TEST_BROWSER_STATIC_PLATFORM_PROVIDERS);

describe('test test', () => {
   //Not really important
});

当我打开浏览器时,控制台中会显示以下错误:

zone.js:323 Error: Error: Cannot resolve all parameters for 'ViewUtils'(RootRenderer, undefined @Inject(Token AppId), SanitizationService). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'ViewUtils' is decorated with Injectable.
    at NoAnnotationError.BaseException [as constructor] (http://127.0.0.1:8080/node_modules/@angular/core/src/facade/exceptions.js:17:23)
    at new NoAnnotationError (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_exceptions.js:217:16)
    at _extractToken (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_provider.js:232:15)
    at eval (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_provider.js:184:45)
    at Array.map (native)
    at _dependenciesFor (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_provider.js:184:19)
    at resolveReflectiveFactory (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_provider.js:72:24)
    at resolveReflectiveProvider (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_provider.js:96:97)
    at Array.map (native)
    at Object.resolveReflectiveProviders (http://127.0.0.1:8080/node_modules/@angular/core/src/di/reflective_provider.js:104:31)
Evaluating http://127.0.0.1:8080/test/areas-list.component.spec.js
Error loading http://127.0.0.1:8080/test/areas-list.component.spec.js

有人知道问题是什么吗?提前谢谢!

1 个答案:

答案 0 :(得分:1)

您是否尝试使用浏览器静态实现任何特定情况?

这是基本配置:

import { setBaseTestProviders } from '@angular/core/testing';
import {
  TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS,
  TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
} from '@angular/platform-browser-dynamic/testing';

setBaseTestProviders(TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);