5
所以,我實現了Redux店的可能不是最好的,我的玩笑的知識是最小的無以倫..玩笑模塊使用終極版 - 模擬店模擬終極版店的getState()
我有三個文件,這包括...
- 模塊
- 一個陣營組件
- 的(正常的)存儲,導出爲默認
我的測試文件看起來像這樣:
// 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)
})
});
爲什麼我嘲笑店的原因是因爲內部<Component />
我使用它本身進口相同store
,認爲正在使用的store.getState()
幾個功能模塊。 ..
那麼這個返回的是
TypeError: _store2.default.getState is not a function
我沒有解決這個問題的嘲諷模塊調用(W這是由<Component />
使用),但我覺得我「應該」能夠做到這一點,因爲我有不同的初始狀態,我想嘗試,而不是所有都依賴於模塊。
這是我的第一篇文章,讓我知道如果我應該澄清任何事情!