I have an immutable record with a field:
Record({
favorite: false
})
By default, ImmutableJS records have the set method to update fields in the record.
When I click on an icon in the same page, it will trigger a method favoriteItem that sets the favorite field to be true:
const favoriteItem = item => {
item.set(favorite, true)
}
Now, I want to test this flow where a user clicks on the icon and favourites the item using Jest.
I set up my test like this:
const mockItem = Record({
favorite: false
})
const user = userEvent.setup()
const favoriteIcon = screen.getByTestId('favorite-icon')
await user.click(favoriteIcon)
But when I run the Jest test, I get the error:
Error: Uncaught [TypeError: item.set is not a function]
This looks really basic but I can't see what's going wrong here...