Jest is a JavaScript testing framework that is developed and maintained by Facebook.
It is designed to be fast, flexible, and easy to use, and it can be used to test the functionality of JavaScript code in a variety of contexts, including web applications, Node.js servers, and more.
Jest is built on top of Jasmine, a popular testing framework for JavaScript, and it includes a number of features that make it easy to write and run tests, including a command-line interface, automatic test discovery, and support for snapshot testing.
Jest is widely used in the JavaScript development community and is well-documented, with extensive documentation available online.
Jest는 페이스북에 의해 개발되어 관리되는 자바스크립트 테스팅 프레임워크입니다.
빠르고 유연하며 사용하기 쉽도록 설계되었으며, 웹 응용 프로그램, Node.js 서버 등 다양한 컨텍스트에서 JavaScript 코드의 기능을 테스트하는 데 사용될 수 있습니다.
Jest는 JavaScript의 인기있는 테스트 프레임워크인 Jasmine 위에 구축되었으며 커맨드라인 인터페이스, 자동 테스트 검색 및 스냅 샷 테스트 지원을 포함하여 테스트를 쉽게 작성하고 실행할 수 있는 여러 기능이 포함되어 있습니다.
Jest는 자바스크립트 개발 커뮤니티에서 널리 사용되며 문서화가 잘 되어 있고 온라인에서 광범위한 문서를 이용할 수 있습니다.
Install Jest: Before you can use Jest, you need to install it. You can do this by running npm install --save-dev jest in your terminal. This will install Jest and add it to the devDependencies section of your package.json file.
npm install --save-dev jest
Write test cases: To use Jest, you need to write test cases for your code. A test case is a function that tests a specific aspect of your code and verifies that it is working correctly. Test cases are usually written using the test function provided by Jest, which takes a string description of the test case as its first argument and a function containing the code to be tested as its second argument.
// math.test.js
function add(a, b) {
return a + b;
}
test('adds 1 + 2 to equal 3', () => {
expect(add(1, 2)).toBe(3);
});
Run test cases: To run your test cases with Jest, you can use the jest command in your terminal. This will execute all of the test cases in your project and display the results.
Debug test cases: If a test case fails, you can use Jest's built-in debugging tools to figure out why. Jest provides a number of functions and features that you can use to debug your test cases, including the ability to run test cases in isolation, the ability to inspect the values of variables at different points in the test case, and the ability to pause the execution of the test case and interact with it using the debugger.
Learn more about Jest: There are many more features and capabilities of Jest that you can learn about as you continue to use it. You can find more information about Jest in its documentation and in the many tutorials and resources available online(https://jestjs.io/).
npm install --save-dev jest 를 Terminal에 입력하여 실행시킬 수 있습니다. 이 명령줄은 Jest를 설치하고 pacakage.json 파일 안 구역에 devDependencies 를 추가합니다.test 함수를 사용하여 작성되는데, 이 함수는 테스트 케이스의 문자열 설명을 첫 번째 인수로 사용하고 테스트할 코드를 포함하는 함수를 두 번째 인자로 사용합니다.jest 명령어를 터미널에서 사영할 수 있습니다. jest 명령어는 프로젝트의 모든 테스트 케이스를 실행하고 그에 대한 결과를 표시합니다.Jest의 내장 디버깅 도구를 사용하여 그 이유를 파악할 수 있습니다. Jest 는 테스트 케이스를 분리하여 실행하는 기능, 테스트 케이스의 다른 지점에서 변수 값을 검사하는 기능, 테스트 케이스의 실행을 일시 중지하고 디버거를 사용하여 테스트 케이스와 상호작용 하는 기능 등 테스트 케이스를 디버깅하는 데 사용할 수 있는 여러 기능과 함수를 제공합니다.Jest 에는 Jest를 계속 사용하면서 배울 수 있는 여러가지 기능이 더욱 많이 있습니다. Jest에 대한 자세한 내용은 설명서와 온라인으로 제공되는 자습서 및 리소스(https://jestjs.io/)에서 확인 할 수 있습니다.@types/jest package: This package provides type definitions for Jest, which will help you avoid type errors when writing your tests. You can install it by running the following command:npm install --save-dev @types/jest
ts-jest preprocessor. You can do this by adding the following section to your package.json file:"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
}
}
.ts or .tsx file extension for your test files, and Jest will automatically compile them using ts-jest.expect function from Jest's @jest/types package, which provides type-safe assertions that can help you avoid type errors.-noEmit flag: When running Jest with TypeScript, it's a good idea to use the -noEmit flag to prevent Jest from generating any JavaScript files. This will ensure that Jest only runs the TypeScript compiler and does not generate any output files.@types/jest package: types/jest 패키지는 Jest에 대한 유형 정의를 제공하므로 테스트를 작성할 때 타입 유형 오류를 방지할 수 있습니다.ts-jest 전처리기를 Jest가 사용하도록 구성해야 합니다..ts 나 .tsx 를 사용할 수 있고, Jest는 ts-jest 를 사용하여 자동으로 컴파일합니다.@jest/types package의 type-safe한 assertion를 제공하여 타입 에러를 회피하도록 도와주는 expect 함수를 사용하는것이 좋습니다.--noEmit flag: TypeScript와 함께 Jest를 실행시킬 때 Jest가 다른 자바스크립트 파일을 생성하지 못하도록 --noEmit 플래그를 사용하는 것이 좋습니다. 이 플래그는 Jest가 오직 TypeScript 컴파일러만 실행하고 다른 출력 파일들을 생성하지 않는 것을 보장합니다.ts-jest documentation: Jest uses the ts-jest preprocessor to compile TypeScript code when running tests. The ts-jest documentation, which is available at https://kulshekhar.github.io/ts-jest/, includes detailed information about how to configure and use ts-jest, as well as information about the various options that are available.ts-jest documentation: Jest는 TypeScript 코드를 실행시킬 때 ts-jest 전처리기를 사용합니다. https://kulshekhar.github.io/ts-jest/ 에서 제공되는 ts-jest 문서에는 ts-jest 를 구성하고 사용하는 방법에 대한 자세한 정보와 함께 사용 가능한 다양한 옵션에 대한 정보가 포함되어 있습니다.