jest
-
Jest did not exit one second after the test run has completed.테스팅/JEST 2019. 11. 6. 16:36
1. 문제 HTTP API 통신 테스트를 하다가 다음과 같은 경고를 만났다. Jest did not exit one second after the test run has completed. This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue. 2. 해결 테스트 실행 완료 후 1초 동안 Jest가 종료되지 않았다. 이 뜻은 테스트의 비동기 작업들이 종료되지 않았다는 것이다. 그래서 Jest를 실행할 때, '--detectOpenHandles' 옵션을 사용하는..
-
-
-
-
-
-
expect.anything()테스팅/JEST 2019. 10. 21. 12:53
anything()은 null이나 undefined을 제외한 모든 값들과 일치한다. 이게 무슨 말이냐면 null, undefined외의 모든 값과 비교했을 때 동일하다는 결과를 기대한다는 것이다. 이는 null, undefined를 제외한 모든 값의 상태를 허용할 때 사용한다. # 리터럴 값 아래의 코드를 보자. test('map calls its argument with a non-null argument', () => { const mock = jest.fn(); [1].map(x => mock(x)); expect(mock).toBeCalledWith(1); }); 길이가 1인 배열에 map()을 통해 익명함수를 정의했다. 익명함수 안에서 mock()을 호출하는 코드를 작성했다. 만약 이것이 실행된..
-
expect.extend()테스팅/JEST 2019. 10. 18. 15:58
1. expect.extend() extend()는 matcher를 구현할 수 있는 함수다. JEST가 제공해주는 matcher 중 내가 원하는 matcher가 없는 경우 직접 구현할 수가 있게 제공한다. 예를 들어서, 숫자 범위를 검증하는 테스트가 필요하다고 해보자. 이 경우, 기본 제공하는 matcher기능(toBeLessThan(), toBeGreatherThan())으로도 테스트를 해볼 수 있지만 2번의 matcher를 호출해야하므로 불편할 수 있다. 그러니 직접 범위를 검증하는 matcher를 만들어보자. 1. expectExtend.test.js 파일을 하나 만들고 아래의 matcher 생성 코드를 작성하자. expect.extend({ toBeWithinRange(received, floor..