我在测试Reflux操作在我的应用程序中正确触发时遇到了困难,事实上它们似乎并没有与Jest一起工作.我有这个例子测试:
jest.autoMockOff();
describe('Test', function () {
it('Tests actions', function () {
var Reflux = require('../node_modules/reflux/index');
var action = Reflux.createAction('action');
var mockFn = jest.genMockFn();
var store = Reflux.createStore({
init: function () {
this.listenTo(action, this.onAction);
},
onAction: function () {
mockFn();
}
});
action('Hello World');
expect(mockFn).toBeCalled();
});
});
Run Code Online (Sandbox Code Playgroud)
哪个输出:
? Test › it Tests actions
- Expected Function to be called.
at Spec.<anonymous> (__tests__/Test.js:20:20)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
Run Code Online (Sandbox Code Playgroud)
即使使用Jasmine异步功能,它似乎也不起作用
jest.autoMockOff();
describe('Test', function () {
it('Tests actions', function () {
var Reflux …Run Code Online (Sandbox Code Playgroud)