如何在Jest中模拟命名的导出

时间:2019-01-29 15:25:28

标签: mocking jestjs

我正在使用“ react-device-detect”,并试图模拟它公开的名为“ isMobile”的导出,以测试我的组件,但是无法这样做。

import { isMobile } from 'react-device-detect';

const Component = () => {
  isMobile ? return 'MOBILE' : 'DESKTOP'
}
export default Component;

如何模拟isMobile const以测试我的不同输出? 我尝试了以下操作,但在玩笑的默认上下文中,isMobile始终返回false。

import Component from './Component';

jest.mock('react-device-detect', () => ({ isMobile: true }));
expect(shallow(<Cmp />)).toBe('DESKTOP');

0 个答案:

没有答案
相关问题