easy-peasy icon indicating copy to clipboard operation
easy-peasy copied to clipboard

getMockedActions returning "@thunk.<thunk_name>(start)" type thunk but not "@thunk.<thunk_name>(fail)" when the thunk throws an error

Open LuisOsta opened this issue 5 years ago • 2 comments

The Problem

This was working a couple of weeks back so I'm unsure why it's failing now. Essentially I'm writing a test case that a thunk fails when I expected it to.

As it's shown in the tutorial.

The store.getMockedActions() should return both the start of the thunk and the failed state of the thunk (if it fails).

Kinda like this (abbreviated example from the tutorial:

[
    { type: '@thunk.fetchById(start)', payload: todo.id },
    { type: '@thunk.fetchById', payload: todo.id },
]

But what I get from the functions is this:

[
    { type: '@thunk.fetchById(start)', payload: todo.id },
]

The Question

Do you have a sense of what could be causing this issue? And if there's anything recent that could be causing it?

More Information

Test Runner

  • Jest

Store Configuration

const store = createStore(storeModel, {
      injections: {
        authService: mockAuthService,
      },
      mockActions: true,
});

Test Case In Question

test("The user should not be signed up if they provide an invalid email", async () => {
        const invalidUser = {
          ...signUpUser,
          email: "[email protected]",
        };

        expect(mockAuthService.signUp).not.toHaveBeenCalled();

        await expect(
          store.getActions().user.signUp(invalidUser)
        ).rejects.toThrow(Error("The email provided was not valid."));

        expect(mockAuthService.signUp).not.toHaveBeenCalled();
        expect(store.getMockedActions()).toEqual(
          expect.arrayContaining([
            {
              type: "@thunk.user.signUp(fail)",
              payload: invalidUser,
              error: Error("The email provided was not valid."),
            },
          ])
        );
});

LuisOsta avatar Oct 26 '20 15:10 LuisOsta

Hi @LuisOsta - what version are you using?

ctrlplusb avatar Oct 27 '20 20:10 ctrlplusb

@ctrlplusb Oh sorry for not including that info in the original one, slipped my mind. The version used when I run npm list easy-peasy is 4.0.1

LuisOsta avatar Oct 27 '20 20:10 LuisOsta