我开始研究使用Jasmine和Karma的打字稿项目。不幸的是,Karma无法执行已编译的单元测试,Chrome中出现此错误:
appbar.addOnOffsetChangedListener(new OnOffsetChangedListener() {
@Override
public void onOffsetChanged(final AppBarLayout appBarLayout, final int verticalOffset) {
float offsetAlpha = (appBarLayout.getY() / appbar.getTotalScrollRange());
blurView.setAlpha( 1 - (offsetAlpha * -1));
}
});
示例项目 - 我相信这是演示此问题的最简单的配置:
的package.json:
Uncaught ReferenceError: define is not defined
karma.conf.js:
{
"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"
}
}
TS / tsconfig:
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 / helloworld.ts
{
"compilerOptions": {
"target": "es5"
,"module": "amd"
,"lib": [ "es2015", "dom" ]
,"outDir": "../js"
}
}
TS / helloworld.spec.ts
function returnHello() : string {
return "Hello";
}
export default returnHello;
答案 0 :(得分:1)
我的解决方案基于这个问题:karma jasmine with angular & requirejs
我向github上传了一个工作示例: https://github.com/nagyzsolthun/typescript-amd-karma