2017-05-05 85 views
0

我想用Jest測試這部分代碼,但我遇到了一些問題。在Jest測試中更改「module」對象中的值

我調用函數之前tryed只是改變了值:

module.hot = { accept: jest.fn() } 
console.log(module.hot) // This print the assigned value 
... 
configureStore({ initialState, history }) 

module.hot值沒有被調用的函數設置。

const configureStore = ({ initialState, history }) => { 
... 
    console.log(module.hot) // This print "undefined" 
    if (module.hot) { 
    module.hot.accept('reducers',() => { 
     store.replaceReducer(reducers) 
    }) 
    } 
} 

Jest是否以某種特定方式管理'模塊'對象?

回答

-1

,是你的模塊中原因module住在全局命名空間,這就是爲什麼你必須有設置:

global.module = {hot: jest.fn()}