开玩笑嘲笑特定功能

时间:2019-12-25 12:12:16

标签: javascript jestjs

我已经开始使用玩笑了,但是在模拟特定的JS函数时遇到了一些麻烦,我已经尝试过各种解决方案,但是我无法使其正常工作。

下面是我的JavaScript函数代码

functions.js:

function test1(){

return "hello1"
}

function test2(){

return "hello2"
}
module.exports = test1;
module.exports = test2;

这是我开玩笑的代码:

function.test.js

const testfunction = require('/function');

test('tooltip Correct DOM element test', () => {
    expect(testfunction.test1).toBe("hello1");
    });

1 个答案:

答案 0 :(得分:1)

您导出的函数不正确。您需要这样做:

function test1() {
  return "hello1"
}

function test2() {
  return "hello2"
}
module.exports = {
  test1: test1,
  test2: test2
};

以这种方式导出功能将使testfunction.test1进入测试文件。而且您需要像下面这样在测试脚本中调用函数:

expect(testfunction.test1()).toBe("hello1");