代码之家  ›  专栏  ›  技术社区  ›  user762579

是开玩笑。嘲笑()相当于信噪比()

  •  1
  • user762579  · 技术社区  · 6 年前

    在所有的例子中,Firebase SDK for Cloud Functions Quickstart、Mocha/Chai和Sinon都使用了。。。我想用笑话来代替,我想知道什么才是正确的等价物信噪比() ?

    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 回复  |  直到 6 年前
        1
  •  2
  •   user762579 user762579    6 年前

    mocking-es-and-commonjs-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()