我正在尝试测试redux连接的反应组分 .

getPref(value) {
        const { dispatch } = this.props;
        dispatch(getUserValue(value)).then(data => {
    this.setState({preferences, data});
        }, (err) => {
    this.setState({error, err});
        });
    }

测试用例如下

describe('pref', () => {
                it('Should update the state correctly with pref',() => {
                    let store = mockStore({…mockPref});
                    const el = setup({ 
                        store: store, 
                        dispatch: jest.fn(jest.fn()).mockReturnValueOnce(Promise.resolve(“any user”))
                    });
                    el.instance(). getPref(‘123’);
                    const expected = “any user”;
                    expect(el.state(). pref).toEqual(expected);    
                });                       
            });

Mock 不按预期工作,它没有回归嘲笑的承诺 . 相反,它正在调用实际方法 .