angular2 testing, error in ViewUtils when using setBaseTestProviders()

By : ab1207
Source: Stackoverflow.com
Question!

When using the method 'setBaseTestProviders(..)', an error pops up in the console.

We're using angular-2.0.0-rc.1.

The test (test/areas-list.component.spec.ts) is as follows:

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
});

When I open the browser, the following error is shown in the console:

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

Does somebody know what the problem is? Thanks in advance!

By : ab1207


Answers

Is there any specific case you're trying to achieve with browser static?

Here is the basic config:

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


This video can help you solving your question :)
By: admin