无法在 Jade 测试脚本中使用 toBeCalled()

Can't get toBeCalled() working in Jade test script

我无法在我的 Jade 测试脚本中运行 toBeCalled()

我在 运行 Jade 测试时收到以下错误消息:

Error: toBeCalled() should be used on a mock function or a jasmine spy

我打电话给 jest.unmock('../fooey'),所以不确定为什么会收到错误消息?

fooey.js

var foo = function(phrase) {
    return bar(phrase);
}

var bar = function(greeting) {
    console.log(greeting + " Watz up?");
}

foo("Hi Bob!");

module.exports.foo = foo;

module.exports.bar = bar;

fooey-test.js:

jest.unmock('../fooey'); // unmock to use the actual implementation.

describe('fooey()', () => {

   const foo = require('../fooey').foo;
   const bar = require('../fooey').bar;

   it('bar() is called.', () => {

      foo("Hi Bob!");

      expect(bar).toBeCalled();
   });
});

我用 bar() 的 mock 和 spyOn() 都得到了它...

fooey.js

var Fooey = function() {
    // var self = this;

    this.foo = function(phrase) {
        // var result = self.bar(phrase);
        var result = this.bar(phrase);

        return result;
        // return "Junky."
    };

    this.bar = function(greeting) {
        var result = greeting + " Watz up?"

        console.log(result);

        return result;
    };
};


module.exports = Fooey;

fooey-test.js

jest.unmock('../fooey'); // unmock to use the actual implementation.

describe('fooey()', () => {

   const Fooey = require('../fooey');
   const fooey = new Fooey();

  it('mock: bar() is called.', () => {

      var myFooey = {
         foo: fooey.foo,
         bar: jest.genMockFunction()         
      };

      myFooey.foo("Hello");

      expect(myFooey.bar).toBeCalledWith("Hello");
   });

   it('bar() is called with "Hi Bob!".', () => {

      spyOn(fooey, 'bar');

      fooey.foo("Hi Bob!");

      expect(fooey.bar).toHaveBeenCalledWith("Hi Bob!");
   });
});