请原谅我只是在 Angular 2 的单元测试中进行尝试。这个奇怪的错误出现在执行npm run test
. 可能是一个小错误,但无法解决这个奇怪的错误:
import { TestBed, async, inject } from '@angular/core/testing';
import { TestModule } from '../../test/test.module';
import { DevExtremeModule } from 'devextreme-angular';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpModule, XHRBackend, RequestOptions } from '@angular/http';
import { Templates } from './templates.component';
import { CommandButton } from '../../common/tool/command-button.component';
import { NgReduxModule, NgRedux } from '@angular-redux/store/lib';
import { MockBackend } from "@angular/http/testing/mock_backend";
import { HttpService } from "../../services/http.service";
import { AppState } from '../../redux/index';
// Mock out the NgRedux class with just enough to test what we want.
class MockRedux extends NgRedux<AppState> {
constructor(private state: AppState) {
super(null);
}
dispatch = () => undefined;
getState = () => this.state;
}
describe('Component : Templates', () => {
let fixture;
let mockRedux: NgRedux<AppState>;
let mockState : AppState = {
session : { token: '', user: { firstName : 'Test User' }, isError: null }
};
beforeEach(done => {
mockRedux = new MockRedux(mockState);
const configure = (testBed: TestBed) => {
testBed.configureTestingModule({
imports: [ TestModule, DevExtremeModule,
RouterTestingModule, HttpModule ],
declarations : [ Templates ],
providers: [
{ provide: XHRBackend, useClass: MockBackend },
{
provide: HttpService,
useFactory: (backend: XHRBackend, options: RequestOptions, redux: NgRedux<AppState> ) => {
return new HttpService(backend, options, mockRedux );
},
deps: [XHRBackend, RequestOptions]
},
{ provide: NgRedux, useClass : mockRedux }
]
});
};
TestModule.configureTests(configure).then(testBed => {
fixture = testBed.createComponent(RegTemplates);
fixture.detectChanges();
done();
});
});
it('should instantiate Templates Component', async(inject([], () => {
fixture.whenStable().then(() => {
fixture.autoDetectChanges();
expect(fixture.componentInstance).toBeDefined();
});
})));
// To do
});
错误说:
TypeError: jit__object_Object_38 is not a constructor