【发布时间】:2018-09-18 18:10:29
【问题描述】:
我正在尝试使用 mocha 和 should.js 编写一些单元测试,因为我想保持每个单元测试的格式相同,并且每个单元测试都需要 should.js 来验证对象的属性。如何将其设置为全局变量,因此到目前为止我已经尝试过的每个测试文件都不需要 should.js
global.should = require('should');
describe('try gloabl'), () => {
it('should work'), () => {
let user = { name: 'test'};
global.should(user).have.property('name', 'test');
});
});
#error, global.should is not a function
如果我使用它。它有效
const should = require('should');
should = require('should');
describe('try gloabl'), () => {
it('should work'), () => {
let user = { name: 'test'};
global.should(user).have.property('name', 'test');
});
});
【问题讨论】:
标签: javascript node.js global-variables mocha.js should.js