是否有使用Jasmine将代码与测试分开的标准方法?
== functions.js
function sample() {
return true;
}
== functions.spec.js
describe('functions', function () {
it('sample', function () {
expect(sample()).toEqual(true);
});
});
== karma.config.js
module.exports = function (config) {
config.set({
basePath: __dirname + '/../public/',
frameworks: [
'jasmine'
],
browsers : ['PhantomJS'],
client: {
jasmine: {
stopOnFailure: true
}
},
files: [
'js/**/*.spec.js'
]
});
};
提前致谢!
我试图使用' browserify'没有成功:
== karma.config.js
browserify: {
debug: true,
plugin: ['proxyquireify/plugin'],
extensions: ['.js']
},
preprocessors: {
'js/**/*.spec.js': ['browserify']
}
== functions.spec.js
var source = require('./functions.js');
...
expect(source.sample()).toEqual(true);
答案 0 :(得分:0)
原始文件中的一处小改动有助于:
== functions.js
this.sample = function() {
return true;
};