nev*_*gqs 4 javascript mocha.js node.js
鉴于这样的事情:
it('uses env variables correctly', function(done) {
assert.equal(process.env.x * process.env.y, 10);
});
Run Code Online (Sandbox Code Playgroud)
我想为这一个测试设置x和y环境变量.那可能吗?
Leo*_*tny 13
这是最常见的方法:
describe('env', function () {
var env;
// mocking an environment
before(function () {
env = process.env;
process.env = { x: 2, y: 5 };
});
// running tests
it('uses env variables correctly', function (done) {
assert.equal(process.env.x * process.env.y, 10);
done();
});
// restoring everything back
after(function () {
process.env = env;
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4310 次 |
| 最近记录: |