2017-07-07 81 views
0

我开始使用Jasmine和Karma打字的项目。不幸的是噶无法在Chrome执行编译单元测试,与此错误:Karma Typescript helloworld示例失败

Uncaught ReferenceError: define is not defined 

示例项目 - 我认为这是最简单的配置来证明这个问题:

的package.json:

{ 
    "name": "HelloWorld", 
    "scripts": { 
    "build": "tsc -p ts", 
    "test": "./node_modules/karma/bin/karma start karma.conf.js" 
    }, 
    "devDependencies": { 
    "typescript": "~2.4.1" 
    ,"jasmine-core": "2.6.4" 
    ,"jasmine": "2.6.0" 
    ,"@types/jasmine": "2.5.53" 
    ,"karma": "1.7.0" 
    ,"karma-chrome-launcher": "^2.2.0" 
    ,"karma-jasmine": "^1.1.0" 
    } 
} 

karma.conf.js:

module.exports = function(config) { 
    config.set({ 
    frameworks: ['jasmine'], 
    files: ['js/*.spec.js'], 
    reporters: ['progress'], 
    port: 9876, 
    colors: true, 
    logLevel: config.LOG_INFO, 
    autoWatch: true, 
    browsers: ['Chrome'], 
    singleRun: false, 
    concurrency: Infinity 
    }) 
} 

TS/tsconfig:

{ 
    "compilerOptions": { 
    "target": "es5" 
    ,"module": "amd" 
    ,"lib": [ "es2015", "dom" ] 
    ,"outDir": "../js" 
    } 
} 

TS/helloworld.ts

function returnHello() : string { 
    return "Hello"; 
} 

export default returnHello; 

TS/helloworld.spec.ts

import returnHello from "helloworld"; 

describe("Some Test", function() { 
    it("passes",() => expect(returnHello()).toEqual("Hello")); 
}); 
+0

有趣的是,从来没有想过甚至试图在角项目之外运行茉莉花/业力。您正在测试的是后端还是前端代码? – seescode

+0

它的前端代码。 –

+0

[karma jasmine with angular&requirejs]的可能重复(https://stackoverflow.com/questions/23689671/karma-jasmine-with-angular-requirejs) – Louis

回答