我正在使用Angular 2和TypeScript。我使用Angular CLI工具創建了這個項目,並嘗試使用命令「karma start」在內部運行測試用例 - 「app.component.spec.ts」。這個測試用例由Angular CLI本身生成,並且沒有變化。 當我運行它給了我下面的錯誤測試用例 -Angular CLI:使用karma測試執行時出現「意外的令牌導入」
C:\Projects\Angular2\TestProject>karma start
21 08 2016 16:18:34.167:WARN [karma]: No captured browser, open http://localhost:9876/
21 08 2016 16:18:34.178:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
21 08 2016 16:18:34.205:INFO [launcher]: Starting browser Chrome
21 08 2016 16:18:36.677:INFO [Chrome 52.0.2743 (Windows 7 0.0.0)]: Connected on socket /#u3qiejjLaOGa5HdGAAAA with id 54026183
Chrome 52.0.2743 (Windows 7 0.0.0) ERROR
Uncaught SyntaxError: Unexpected token import
at C:/Projects/Angular2/TestProject/src/app/app.component.spec.ts:5
可能有人請幫助如何解決這個問題。
app.component.spec.ts -
/* tslint:disable:no-unused-variable */
/// <reference path="../../typings/globals/jasmine/index.d.ts" />
import { addProviders, async, inject } from '@angular/core/testing';
import { AppComponent } from './app.component';
describe('App: TestProject',() => {
beforeEach(() => {
addProviders([AppComponent]);
});
it('should create the app',
inject([AppComponent], (app: AppComponent) => {
expect(app).toBeTruthy();
}));
it('should have as title \'app works!\'',
inject([AppComponent], (app: AppComponent) => {
expect(app.title).toEqual('Test Project Title');
}));
});
您正在使用哪個IDE? – TypeScripter
Visual Studio代碼 – Raj
無論哪個IDE或終端,我都面臨同樣的問題。第一個導入始終引發「未捕獲的SyntaxError:意外的令牌導入」。 – Guntram