redux-utilities / redux-actions

Flux Standard Action utilities for Redux.
https://redux-actions.js.org
MIT License
6.51k stars 301 forks source link

Wierd behavior with just not recognizing string templated reducer #381

Closed lemiesz closed 1 year ago

lemiesz commented 2 years ago

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 commented 1 year ago

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.