React

ESLint + Jest) 'test' is not defined

ESLint로 안티패턴을 방지하면서 알고리즘 문제를 푸는 것도 필요하다는 생각이 들어 기존에 알고리즘 문제를 풀던 CodingTest 프로젝트 내에 jsProj에 있는 ESLint 관련된 package.json 파일을 가져와서 npm install 했다. 이후 많은 에러들을 봤지만 save해주면 자동적으로 수정해주기 때문에 위의 에러만 해결하면 됐다.
jest를 능숙하게 사용하는 것이 아니라 코딩테스트에 한에서 사용하기 때문에 어떻게 해결해줄지 몰라서 구글링을 해보았다.
글을 참고해보니 node로 해결하는 방법과 ESLlint로 해결하는 방법이 나뉘었다.

Node

If you want to run them directly through node, try to require jest and/or jest-runtime. Also give @types/jest a try as well.
Check Edit 2 for new info about this
Edit
@types/jest (jest-DefinitelyTyped) is definitely needed (or just one solution). If you install it (e.g., dev dependency), the IDE errors should go away. I just tried it on Webstorm, and it works.
@types/jest(jest-DefinitelyTyped)는 반드시 필요합니다(또는 단 하나의 솔루션). 설치하면(예: 개발 종속성) IDE 오류가 사라집니다. 방금 Webstorm에서 시도했는데 작동합니다.
Edit 2
The new Jest@20 Matchers (e.g., .resolves and .rejects) are still not defined in @types/jest. You can keep track of its status on the links below: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/16645 https://github.com/DefinitelyTyped/DefinitelyTyped/issues/16803
새로운 Jest@20 Matchers(예: .resolves 및 .rejects)는 여전히 @types/jest에 정의되어 있지 않습니다. 링크에서 상태를 추적할 수 있습니다.
Edit 3
The new release (20.0.1) includes the newest Jest definitions.
⇒ 나는 node를 최신 버전으로 사용중이었기 때문에 위의 방식을 넘기고 아래의 Lint로 해결하는 방식을 시도했다.

Lint

this isn't in the scope of this specific problem, but it also helps
Are you using something like ESLint? If so, you'll need eslint-plugin-jest
Following the steps described in this page: https://www.npmjs.com/package/eslint-plugin-jest, you will basically need to add it as an ESLint plugin and set jest globals in the ESLint configuration:
*ESLint**와 같은 것을 사용하고 있습니까? 그렇다면 `eslint-plugin-jest`가 필요합니다. 기본적으로 ESLint 플러그인으로 추가하고 ESLint 구성에서 jest 전역을 설정해야 합니다.
{ "env": { "jest/globals": true } }
Plain Text
복사
If you plan on supporting ES6 tests, you'll also need Babel and babel-jest plugin with the following jest configuration:
"transform": { "^.+\\.js$": "babel-jest" }
Plain Text
복사
Finally, for Typescript tests you'd need the @types/jest and ts-jest packages as well
⇒ 나는 먼저 eslint-plugin-jest를 설치해주었고 .eslintrc.json 파일(여기서 말하는 ESLint config)의 env 프로퍼티 내부에 "jest/globals" : true를 할당했더니 깔끔하게 해결되었다.
// .eslintrc.json { "parser": "babel-eslint", "parserOptions": { "ecmaVersion": 12 }, "env": { "browser": true, "commonjs": true, "es2021": true, "node": true, "jest/globals": true // "jest" 여도 된다. },
JavaScript
복사