Using Matchers (ok)
https://jestjs.io/docs/using-matchers
Common Matchers
The simplest way to test a value is with exact equality.
test('two plus two is four', () => {
expect(2 + 2).toBe(4);
});test('object assignment', () => {
const data = {one: 1};
data['two'] = 2;
expect(data).toEqual({one: 1, two: 2});
});toEqual kiểm tra đệ quy mọi trường của một đối tượng hoặc mảng.
test('object assignment', () => {
const data = {one: 1};
data['two'] = 2;
expect(data).toEqual({one: 1, two: 2});
});You can also test for the opposite of a matcher:
Truthiness
Trong các bài kiểm tra, đôi khi bạn cần phân biệt giữa không xác định, null và sai, nhưng đôi khi bạn không muốn xử lý chúng theo cách khác nhau. Jest chứa những người trợ giúp cho phép bạn rõ ràng về những gì bạn muốn.
Numbers
For floating point equality, use toBeCloseTo instead of toEqual, because you don't want a test to depend on a tiny rounding error.
toBeCloseTo instead of toEqual, because you don't want a test to depend on a tiny rounding error.Strings
Arrays and iterables
Exceptions
Last updated