Jest for vuex, test different return values for a same action

After a lot of trial and error I found just the right mix of nexttick and forceupdate that makes the code work.

    actions.create = () => Promise.resolve({ code: false });
    store.hotUpdate({ actions });
    await wrapper.vm.$forceUpdate();
    wrapper.vm.create();
    await wrapper.vm.$nextTick();
    await wrapper.vm.$forceUpdate();
    expect(wrapper.vm.$data.status).toEqual('success');

If I remove the nexttick or either of the forceupdate, the test doesn’t pass.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top