Redux & Redux Toolkit Course
Redux & Redux Toolkit
/
Beginner

Testing Actions

Definition

Verifying that Action Creators return the correctly formatted plain JavaScript object with the correct `type` and `payload`.

Explain Like I'm New

In modern RTK, testing actions is largely unnecessary because `createSlice` generates them perfectly every time. However, in legacy Redux, you had to manually test that your action creator functions didn't have typos.

Real World Example

Testing that `addTodo('Buy Milk')` actually returns `{ type: 'ADD_TODO', payload: 'Buy Milk' }`.

Common Use Cases

  • •Legacy Redux codebases

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • Is it highly necessary to test actions generated by RTK's `createSlice`?

intermediate

  • What property must you always verify in an Action test?

Flash Cards

Question

Necessary for RTK?

Click to reveal answer
Answer

No. RTK is rigorously tested by its maintainers. You don't need to test that `createSlice` works. You should focus on testing your custom Reducer logic.

Question

Which property?

Click to reveal answer
Answer

The `type` property. If the type is wrong, the reducer will ignore the action completely.