我有一个mixin/Utils.js
要测试的地方underscore
,模块中需要和使用的地方。就像是:
var _ = require('underscore');
var Utils = {
foo: function(arrayOfArray) {
return _.sortBy(arrayOfArray, function(array) {
return -1 * array[1].length;
}) || {};
}
};
module.exports = Utils;
当我尝试使用 Jest 对其进行测试时,我做了如下的事情。但是测试失败了。我有一种感觉,因为我没有嘲笑underscore
. 但是我应该如何嘲笑呢?一般来说,如果模块具有类似的依赖项underscore
,我应该如何正确设置模拟并测试模块?
var __path__ = "PATH_TO/mixins/Utils.js";
jest.dontMock(__path__);
describe("Test for mixins/Utils.js", function() {
var Utils;
beforeEach(function() {
Utils = require(__path__);
});
describe("countInversion", function() {
it('Passing in [[0, [1,2]], [1, [1,2,3]]] and should get [[1, [1,2,3]]],[0, [1,2]] ', function() {
var testInput = [[0, [1,2]], [1, [1,2,3]]];
var expectedOutput = [[1, [1,2,3]]],[0, [1,2]];
expect(Utils.FOO(testInput)).toEqual(expectedOutput);
});
});
});