react-state-rxjs
  • Introduction
  • Main differences
  • Performance first
  • GETTING STARTED
    • Instalation
    • Examples
  • Core concepts
    • Main idea
      • More complex flow visualization
    • Configuration
    • Store
      • Operators
      • Optimistic updates plugin
      • Form manager plugin
        • ShouldUpdateState hook
        • Custom form elements
      • Persist state plugin
        • Configuring custom storage
    • Actions
      • Immer
      • ImutableJs
      • Async
    • Components with Actions
    • @InjectStore decorator
    • @ComponentState decorator
    • ComponentState Hook
    • Dispatcher
    • Router / History
  • DIFFERENT SCENARIOS
    • Passing list item index via router
  • UNIT TESTING
    • Setup
    • Test store
    • Test actions
    • Test component with actions
    • Test with Enzyme
  • Debugging
    • Setup
    • Redux DevTools
    • Automated changes output
    • Manual state changes check
    • Additional debugging information
  • Production
    • Production mode
  • Other information
    • Best practices
    • CLI
      • Custom Configurations
    • Performance
    • Blog Posts
    • Contributing
Powered by GitBook
On this page

Was this helpful?

  1. UNIT TESTING

Test actions

Actions can be tested by calling NgStateTestBed.createActions method. createActions has required param actions and two params with default values: initialState with value {} and statePath with value []. This means that for most of situations we can pass just actions type and test application in localized state. But for more complex scenarios we can pass initial state and path.

it('should return actions', () => {
    const initialState = { todos: [] };
    initialState.todos.push({ description: 'test description' });

    const actions = ReactStateTestBed.createActions<TestActions>(TestActions); // in this case actions will be created with state = {};
    // OR
    const actions = ReactStateTestBed.createActions(TestActions, initialState, ['todos', 0]) as TestActions;
    expect(actions.todoDescription).toEqual('test description');
});

where

  • first param is initialState is object or class

  • second param is statePath to bind actions to

  • third param is actions class

PreviousTest storeNextTest component with actions

Last updated 6 years ago

Was this helpful?