samedi 9 novembre 2019

TypeError: Right-hand side of 'instanceof' is not callable -- react test file

I have been trying to write a test case for a react component using redux I am using UUID to generate the id of an expense so I need to use " expect.any(String) " to test the random id value but I get this error when I run the test
TypeError: Right-hand side of 'instanceof' is not callable

export const addExpense = ({ description = "", note = "", amount = 0, createdAt = 0 } = {}) => ({ type: "ADD_EXPENSE", expense: { id: uuid(), description, note, amount, createdAt } })

/************* test file ****************/

test('should setup add expense action object with provided values', () => { const expenseDate = { description: 'Rent', amount: 109500, createdAt: 1000, note: 'this was last months rent' }; const action = addExpense(expenseDate); expect(action).toEqual({ type: "ADD_EXPENSE", expense: { id: expect.any(String), ...expenseDate } }); });

if I use a regular string like "123abc" instead of " expect.any(String)" in the test file, the test runs correctly and show that the 2 ids are not equal

Aucun commentaire:

Enregistrer un commentaire