I have a problem with TestBed in Angular 2.0.0
beforeEach( async(() => {
TestBed.configureTestingModule({
declarations: [
SomethingComponent
]
}).compileComponents(); // compile template
}));
beforeEach(() => {
fixture = TestBed.createComponent(SomethingComponent);
comp = fixture.componentInstance;
});
it('test', async(() => {
fixture.detectChanges();
expect(true)
}));
Given the component:
@Component({
templateUrl: 'app/components/something/something.component.html'
})
I get the error:
Firefox 48.0.0 (Mac OS X 10.11.0)
Failed: Uncaught (in promise): Failed to load app/components/something/something.component.html
resolvePromise@node_modules/http://ift.tt/2dweKa9
resolvePromise@node_modules/http://ift.tt/2cGd3AR
scheduleResolveOrReject/<@node_modules/http://ift.tt/2dwf3Cb
ZoneDelegate.prototype.invokeTask@node_modules/http://ift.tt/2cGePC3
ProxyZoneSpec.prototype.onInvokeTask@node_modules/http://ift.tt/2dwePL6
ZoneDelegate.prototype.invokeTask@node_modules/http://ift.tt/2cGexey
Zone.prototype.runTask@node_modules/http://ift.tt/2dwfeNG
drainMicroTaskQueue@node_modules/http://ift.tt/2cGeiA7
ZoneTask/this.invoke@node_modules/http://ift.tt/2dwfUCy
I think it might be because the configuration isnt set up right. I am using gulp to precompile TypeScript into JavaScript, and I have the following project structure:
|_ grails-app
|_ frontend
|_ angular
|_ app
| |_ components
| | |_ something
| | |_ something.component.ts
| | |_ something.component.html
| |_ model
| |_ test
| |_ app.module.ts
| |_ app.routing.ts
| |_ main.ts
|_ assets
|_ build
| |_ app
| |_ components
| | |_ something
| | |_ something.component.html
| | |_ something.component.js
| | |_ something.component.js.map
| |_
| |_
| |
|_ node_modules
|_ gulpfile.js
|_ karma.conf.js
|_ karma-test-shim.js
|_ systemjs.config
|_
|_
|
But if I assume that the html file is precompiled, and remove the command '.compileComponents()' from the test, I get the following error:
Firefox 48.0.0 (Mac OS X 10.11.0)
Error: Cannot create the component SomethingComponent as it was not imported into the testing module!
And if I remove the 'async', I get this error:
Firefox 48.0.0 (Mac OS X 10.11.0)
Error: This test module uses the component SomethingComponent which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test.
In karma-test-shim.js, I have:
System.config({
baseURL: '/base/',
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
map: {
'app': '/base/build/app/',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// angular testing umd bundles
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
// other libraries
'rxjs': 'npm:rxjs'
},
packages: {
'app': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
}
}
});
I hope someone can help me figure out, what Im doing wrong in configuration.
Aucun commentaire:
Enregistrer un commentaire