可能是一个愚蠢的问题
我开始使用JEST进行测试。
我有我的js应用程序:
var app={ init:function{ //some code}, ... }
module.exports = app;
还有我的app.test.js:
const {app} = require('../js/index.js')
test('type of variable', () => {
expect(typeof app.someFunction(app.someVar)).toBe("'number");
});
而且我有经典错误:
TypeError: Cannot read property 'someFunction' of undefined
看起来很愚蠢,但是我从客户角度看不清楚这些要求...它与Jest getStarted示例完美配合
我的arbo是
-js
----index.js
-tests
----app.text.js
module.exports = app
以上行返回object {}
,而您正在尝试从破坏行app
中的对象中拾取var {app}
删除{}
const app = require('../js/index.js')
test('type of variable', () => {
expect(typeof app.someFunction(app.someVar)).toBe("'number");
});