Eugenio
Eugenio

Reputation: 25

Jest, test an output string

I've just started using jest, but some things are not clear to me.

For Example, why if a test this function:

const liElement = object => `<li>${object.title}</li>`;

with:

expect(liElement({title: 'example'}).toBe('<li>example</li>'));

Why my test fail?

Upvotes: 0

Views: 930

Answers (1)

AKX
AKX

Reputation: 169041

You'll want to use expect().toEqual() instead of the strict identity check expect().toBe().

expect(liElement({title: 'example'})).toEqual('<li>example</li>');

Upvotes: 1

Related Questions