我正在使用" ava"反应测试的框架,这是一个package.json:
"babel": {
"presets": [
"es2015",
"stage-2",
"react"
]
},
"ava": {
"babel": "inherit",
"require": [
"babel-register"
]
}
测试代码:
import store from '../../app/redux/store';
import test from 'ava';
import * as c from '../../app/constants'
test('languageReducer() should correctly change the dictionary', t => {
store.dispatch({
type: c.LOCALIZE_CHANGE_DICTIONARY,
dictionary: {
a: 1,
b: 2,
c: 3
}
});
t.DeepEqual(store.getState().localizeReducer.dictionary, {a: 1, b: 2, c: 3});
t.is(10, 10);
});
并且出现错误声音:
unsubscribeHistory = history.listen(function (location) {
^
TypeError: Cannot read property 'listen' of undefined
at middleware (/Users/nikita/WebstormProjects/crm_panel/node_modules/redux-simple- router/lib/index.js:72:33)
如何让我的测试访问全局命名空间(窗口,历史记录等)? 谢谢
答案 0 :(得分:0)
您似乎正在尝试使用浏览器模块,尝试使用浏览器全局history
,而不在浏览器中实际运行测试。 AVA尚未在浏览器中运行,但您可以使用jsdom来提供虚假的浏览器环境。我们有recipe for this。