I am trying to create a unit test with Jest to make sure my array called values does not contain falsy values.
This for some reason does not work - the test passes:
const badValues = ['', null, undefined, false, {}, []];
expect(values).toEqual(expect.not.arrayContaining(badValues));
Below code works as expected (test fails), but surely there must be a proper way instead of looping over my values?
for (const value of values) {
expect(value).toBeTruthy();
}
{}nor[]are "falsy".{}is not falsy, while[]is actually falsy. Try[] == falsein your browser.[] ? alert("truthy") : alert("falsy")in your browser.==operator is not a good way to test that.