.toBeTruthy()
Use .toBeTruthy when you don't care what a value is and you want to ensure a value is true in a boolean context. For example, let's say you have some application code that looks like:
drinkSomeLaCroix();
if (thirstInfo()) {
drinkMoreLaCroix();
}
You may not care what thirstInfo returns, specifically - it might return true or a complex object, and your code would still work. So if you want to test that thirstInfo will be truthy after drinking some La Croix, you could write:
test('drinking La Croix leads to having thirst info', () => {
drinkSomeLaCroix();
expect(thirstInfo()).toBeTruthy();
});
In JavaScript, there are six falsy values: false, 0, '', null, undefined, and NaN. Everything else is truthy.
'Node.js > Jest' 카테고리의 다른 글
[AWS-CDK] How to Mock AWS-CDK, DynamoDB (0) | 2022.04.19 |
---|---|
[Jest] How to set up Debug in Visual Studio Code? (0) | 2022.04.16 |
[Jest] Sample Axios Mock Function (0) | 2022.04.16 |
[Jest] set, clear and reset mock/spy/stub implementation (0) | 2022.04.16 |
[Jest] Jest Mock Functions (0) | 2022.04.15 |