admin管理员组文章数量:1398787
In all examples testing of Firebase SDK for Cloud Functions Quickstart, Mocha/Chai and Sinon are used... Trying to use Jest instead , I wonder what is the correct equivalent of sinon.stub() ?
I tried the following (only for testing jest.mock() acceptance...
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');
but I get an error :
1 failing
1) Cloud Functions "before all" hook: TypeError: jest.mock is not a function
I wrong somewhere ... but I cannot get it thanks for feedback
In all examples testing of Firebase SDK for Cloud Functions Quickstart, Mocha/Chai and Sinon are used... Trying to use Jest instead , I wonder what is the correct equivalent of sinon.stub() ?
I tried the following (only for testing jest.mock() acceptance...
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');
but I get an error :
1 failing
1) Cloud Functions "before all" hook: TypeError: jest.mock is not a function
I wrong somewhere ... but I cannot get it thanks for feedback
Share Improve this question edited Dec 4, 2018 at 21:07 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Dec 4, 2018 at 8:47 user762579user7625791 Answer
Reset to default 3SOLVED ...
got a clear understanding from mocking-es-and-monjs-modules-with-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()
本文标签: javascriptIs jestmock() equivalent to sinonstub()Stack Overflow
版权声明:本文标题:javascript - Is jest.mock() equivalent to sinon.stub() - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744121941a2591781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论