作者:火鸟大叔 | 来源:互联网 | 2023-02-01 14:11
所以我对redux-store的实现可能不是最好的,而且我对Jest的了解是最小的.
我有三个文件,包括......
一个模块
反应组件
(正常)商店,默认导出
我的测试文件如下所示:
// file.test.js
jest.mock( 'store', () => jest.fn() )
// external
import React from 'react'
import configureStore from 'redux-mock-store'
// internal
import Component from 'components/Component'
import store from 'store'
describe( 'Test My Component', () => {
const mockStore = configureStore()
it ( 'should equal true', () => {
const initialState = { active: true }
store.mockImplementation(() => mockStore( initialState ))
expect( store.getState().active ).toBe( true )
} )
} );
我嘲笑商店的原因是因为
我正在使用一个模块,它本身导入相同的store
并且拥有一些正在利用的功能store.getState()
......
那么这回归的是什么
TypeError: _store2.default.getState is not a function
我确实通过模拟模块调用(由其使用
)来解决这个问题,但我觉得我"应该"能够做到这一点,因为我有不同的初始状态我想尝试而不是所有都依赖于模块.
这是我关于SO的第一篇文章,让我知道如果我应该澄清任何事情!