mardi 31 mars 2020

How to use Jest to test higher order function for Redux action with nested function

I am using Jest to test a Redux action function fn1. fn1 is a higher order function that wraps fn2. My test is just to make sure fn2 is called when fn1 is executed. Doesn't seems to work. I am thinking about using jest.spyOn, but it doesn't seem to make sense.

myActions.js:

export const fn1 = obj => {
  return strInput => {
    fn2(strInput, obj);
  };
};

export const fn2 = (strInput, obj) => ({name:strInput, obj});

myAction.test.js:

import {fn1, fn2} from myAction.test.js

it("should call fn2", () => {
    fn1({test:"test"})("David")
    expect(fn2).toHaveBeenCalled();
  });

Aucun commentaire:

Enregistrer un commentaire