Angular-cli: ng test fails after updating to the latest angular cli

Created on 1 Oct 2016  路  5Comments  路  Source: angular/angular-cli

Today I finally updated my project to the latest (from webpack.2) but after I fixed all the compilation errors and some API got refactored. I can not run my test anymore.

I am getting this not really descriptive error:

ypeError: Cannot read property 'injector' of null
            at TestBed._createCompilerAndModule (webpack:///projects/updatedCLI/~/@angular/core/testing/test_bed.js:247:0 <- src/test.ts:6951:44)
            at TestBed.compileComponents (webpack:///projects/updatedCLI/~/@angular/core/testing/test_bed.js:201:0 <- src/test.ts:6905:31)
            at Function.TestBed.compileComponents (webpack:///projects/updatedCLI/~/@angular/core/testing/test_bed.js:106:45 <- src/test.ts:6810:67)
            at Object.<anonymous> (webpack:///projects/updatedCLI/src/app/shared/components/widgets/check-box/tests/check-box.component.spec.ts:22:16 <- src/test.ts:59574:28)
            at ZoneDelegate.invoke (webpack:///projects/updatedCLI/~/zone.js/dist/zone.js:203:0 <- src/test.ts:81201:28)
            at ProxyZoneSpec.onInvoke (webpack:///projects/updatedCLI/~/zone.js/dist/proxy.js:72:0 <- src/test.ts:65403:39)
            at ZoneDelegate.invoke (webpack:///projects/updatedCLI/~/zone.js/dist/zone.js:202:0 <- src/test.ts:81200:34)
            at Zone.run (webpack:///projects/updatedCLI/~/zone.js/dist/zone.js:96:0 <- src/test.ts:81094:43)
            at Object.<anonymous> (webpack:///projects/updatedCLI/~/zone.js/dist/jasmine-patch.js:91:27 <- src/test.ts:65139:50)



I tried get rid of all the custom modules, components to see where could be the problem and ended up with this simple test and even this one gives me this error

fdescribe('Describe checkbox  behavior' , () =>
{


    fit('It should should have non null formControl and existing group if standalone. plus name , label' , () =>
    {
        TestBed.configureTestingModule({
            declarations: [
                TestCBBasicBehaviorComponent
            ]
        });

        TestBed.compileComponents();
        let fixtureWrapper = TestBed.createComponent(TestCBBasicBehaviorComponent);
        fixtureWrapper.detectChanges();


    });



});

@Component({
    selector: 'wrapper-comp' ,
    // template: '<w-checkbox [value]="cbValue" [label]="cbLabel" [name]="cbName" (onClick)="onCBClick($event)"></w-checkbox>'
    template: '<input type="checkbox" name="aaa" value="asdf"/>'
})
export class TestCBBasicBehaviorComponent
{

}

ng --version

Could not start watchman; falling back to NodeWatcher for file system events.
Visit http://ember-cli.com/user-guide/#watchman for more info.
angular-cli: 1.0.0-beta.16
node: 4.6.0
os: darwin x64

Any pointers if this is anguler cli issue of more latest final angular 2.000

All 5 comments

update: I tried to run the same test and newly generated CLI project and it works. so it seems something wrong with the udpate procedure ....?

I did other tests and if I run my test directly from AppModule it works. if I run this form my components module this is where it fails. where before it works no problem. Application works when I do ng serve as well.

I found out that here is the place where it fails:

 };
        TestBed.prototype._createCompilerAndModule = function () {
           ..... //some code
            var compilerFactory = this.platform.injector.get(TestingCompilerFactory);

this. platform is NULL, so it seems that the test.ts did not init the TestSuite propertly.

You can see this clearly on screenshots. Example the same test, the same place, one run from AppModule another from ComponentModule.
The difference is the platform and ngModule is NULL. something that supposed to be initialized by

.then(([testing, testingBrowser]) =>
    {
        testing.getTestBed().initTestEnvironment(
            testingBrowser.BrowserDynamicTestingModule ,
            testingBrowser.platformBrowserDynamicTesting()
        );
    })

screen shot 2016-09-30 at 9 07 26 pm
screen shot 2016-09-30 at 9 03 08 pm

Just for the reference if somebody come to the same issue.

changing the:

import { TestBed } from '@angular/core/testing/test_bed';
to

``` import { TestBed } from '@angular/core/testing';

solved my issue. 

@fkolar, Is that right? Your comment shows an empty block, so did you erase the import? That makes no sense to me.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings