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

effectOn actions argument is missing if effectOn is declared before any actions

Open methyl opened this issue 5 years ago • 0 comments

This test passes:

test('it receives the local actions for nested model', () => {
  // ARRANGE
  const store = createStore({
    nested: {
      fired: false,
      todos: [],
      addTodo: action((state, payload) => {
        state.todos.push(payload);
      }),
      onTodosChanged: unstable_effectOn([(state) => state.todos], (actions) => {
        console.log(actions)
        actions.setFired(true);
      }),
      setFired: action((state, payload) => {
        state.fired = payload;
      }),
    }
  });

  // ASSERT
  expect(store.getState().nested.fired).toBe(false);

  // ACT
  store.getActions().nested.addTodo('add onEffect api');

  // ASSERT
  expect(store.getState().nested.fired).toBe(true);
});

This does not:

test('it receives the local actions for nested model', () => {
  // ARRANGE
  const store = createStore({
    nested: {
      fired: false,
      todos: [],
      onTodosChanged: unstable_effectOn([(state) => state.todos], (actions) => {
        console.log(actions)
        actions.setFired(true);
      }),
      addTodo: action((state, payload) => {
        state.todos.push(payload);
      }),
      setFired: action((state, payload) => {
        state.fired = payload;
      }),
    }
  });

  // ASSERT
  expect(store.getState().nested.fired).toBe(false);

  // ACT
  store.getActions().nested.addTodo('add onEffect api');

  // ASSERT
  expect(store.getState().nested.fired).toBe(true);
});

methyl avatar Nov 10 '20 08:11 methyl