Skip to content

Wierd behavior with just not recognizing string templated reducer #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lemiesz opened this issue Oct 28, 2021 · 1 comment
Closed

Wierd behavior with just not recognizing string templated reducer #381

lemiesz opened this issue Oct 28, 2021 · 1 comment

Comments

@lemiesz
Copy link

lemiesz commented Oct 28, 2021

Title should say jest not recognizing string template reducer.

I have my reducer defined as such (simplified from real world use case to maintain main point)

export const setItem = createAction('@common//setItem');
const reducer = handleActions(
    {
        [`${setItem}`]: (state, action: Action) =>
            !action.error ? action.payload : state,
       //other actions not shown
    },
    null,
);

This is a convenient way of reference the action type in sync with the defined action.

Problem is this seems to not work properly in jest. When defined this way the action is never triggered.

If I rewrite it to statically reference the action type

const reducer = handleActions(
    {
        [`@common/setItem`]: (state, action: Action) =>
            !action.error ? action.payload : state,
       //other actions not shown
    },
    null,
);

This executes properly.

Anyway have any idea how I might fix this?

@alexander-heimbuch
Copy link
Contributor

You should be able to reference the action with setItem.toString(). If this is still an issue feel free to comment and I will reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants