从嘲笑测试获得覆盖范围

时间:2019-12-13 13:43:30

标签: javascript unit-testing mocking jestjs

当我尝试使用模拟游戏时,似乎无法获得报道的笑话。场景是:

// file.js

export func1 () {}; // there are many named exports in this file

export apifunc () {}; // this is the function I have mocked

// __mocks__/file.js

export apifunc () {}; // mocked version of apifunc for testing

// file.test.js
import {func0, /*apifunc*/} from './file.js';

// jest.mock('./file.js) - this did not work due to only one mocked function from file.js in a sea of named exports.  It would cause all my other tests to fail.

import { apifunc } from './__mocks__/file.js; // this is what I ended up having to do

test('test the apifunc here', () => {
  // tests all pass
});

我无法在apifunc上获得代码覆盖,也找不到很好的答案

0 个答案:

没有答案
相关问题