我有一个简单的“hello world”项目,我想测试著名的 hélloWorld 函数。
该项目的结构如下:
├── package.json
├── spec
│ ├── helloWorldSpec.js
│ └── support
│ └── jasmine.json
└── src
└── helloWorld.js
以及文件内容:
包.json
{
"name": "jasmineTest",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"jasmine": "~2.1.0"
}
}
规范/helloWorldSpec.js
// var helloWorld = require('../src/helloWorld.js');
describe('Test', function() {
it('it', function() {
helloWorld();
});
});
src/helloWorld.js
function helloWorld() {
return "Hello world!";
}
// module.exports = helloWorld;
规格/支持/jasmine.json
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}
我的问题:
当我跑步时npm install
茉莉花已下载。
=> 好的
当我跑步时./node_modules/jasmine/bin/jasmine.js
我有错误ReferenceError: helloWorld is not defined ReferenceError: helloWorld is not defined
我的问题:
如何访问 helloWord 中包含的方法src/helloWorld.js
在测试范围内不使用 module.exports = xxx。