
Getting Started with JavaScript Testing using Jest
This article was originally published on bmf-tech.com . Overview Let's write JavaScript tests using Jest. Preparation Since we want to use jest and ESModules, we need to install babel-preset-2015. (babel-jest is provided with jest.) npm install --save-dev jest babel-preset-2015 The contents of .babelrc look like this. { "presets" : [ "es2015" ] } The package.json looks like this. { "scripts" : { "test" : "jest" }, "devDependencies" : { "babel-preset-es2015" : "^6.24.1" , "jest" : "^23.6.0" } } The directory structure looks like this. tree -a -I "node_modules" . ├── .babelrc ├── package-lock.json ├── package.json ├── src │ ├── esmodules │ │ └── calc.js │ └── native │ └── calc.js └── test ├── esmodules │ └── calc.test.js └── native └── calc.test.js 6 directories, 7 files There are two patterns for creating test files. Files located under a directory named __tests__ are treated as test files. Files with the extensions *.spec.js or *.test.js are treated as test files. This time, we will us
Continue reading on Dev.to JavaScript
Opens in a new tab


