Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jest.mock()与sinon.stub()等价吗_Javascript_Jestjs_Sinon - Fatal编程技术网

Javascript jest.mock()与sinon.stub()等价吗

Javascript jest.mock()与sinon.stub()等价吗,javascript,jestjs,sinon,Javascript,Jestjs,Sinon,在测试Firebase SDK云功能Quickstart的所有示例中,都使用了Mocha/Chai和Sinon。。。试图改用Jest,我想知道sinon.stub()的正确等价物是什么 我尝试了以下方法(仅用于测试jest.mock()接受度) const sinon = require('sinon'); const jest = require('jest'); describe('Cloud Functions', () => { before(() => {

在测试Firebase SDK云功能Quickstart的所有示例中,都使用了Mocha/Chai和Sinon。。。试图改用Jest,我想知道sinon.stub()的正确等价物是什么

我尝试了以下方法(仅用于测试jest.mock()接受度)

const sinon = require('sinon');

const jest = require('jest');

describe('Cloud Functions', () => {

    before(() => {
      let myFunctions, adminInitStub;
      let adminInitMock;

      adminInitStub = sinon.stub(admin, 'initializeApp');
      adminInitMock = jest.mock(admin, 'initializeApp');

      myFunctions = require('../index');
      myFunctions = require('../index');
但我有一个错误:

1失败

1) 云功能 “一切之前”挂钩: TypeError:jest.mock不是函数

我错在什么地方了。。。但是我不能得到它 感谢您的反馈

已解决

However, when using export with require we would see an error such as:

TypeError: ourCode is not a function

The CommonJS module does not understand the ES Module it is trying to require. This is easily fixed, by adding a .functionNameBeingExported to the require, which for a default export is default.

externalModule.js
const ourCode = () => 'result';
export default ourCode;

testSubject.js
const ourCode = require('./externalModule').default;
// use ourCode()