Jest의 기본 메소드
test('Truthy & Falthy', () => {
expect(null).toBeNull();
expect(undefined).toBeUndefined();
expect(1).toBeDefined();
expect(1).toBeTruthy();
expect(0).toBeFalsy();
});
test('Number', () => {
expect(2).toBeGreaterThan(1);
expect(2).toBeGreaterThanOrEqual(1);
expect(2).toBeLessThan(3);
expect(2).toBeLessThanOrEqual(3);
expect(1.1 + 0.1).toBeCloseTo(1.2); // 소수의 계산을 확인할 때에는 toBe 대신 toBeCloseTo를 쓴다.
});
test('String에서 특정 단어가 포함돼 있는지를 확인할 때', () => {
expect('Christoph').toMatch(/stop/);
});
test('Array에서 특정 값이 포함돼 있는지를 확인할 때', () => {
expect([1, 2, 3]).toContain(1);
expect([1, 2, 3]).not.toContain(4); // not을 사용해서 반대의 경우를 확인할 수 있다.
});
참고 : https://jestjs.io/docs/en/using-matchers
함께 쓰면 좋은 Visual Studio Code 익스텐션