Jest - Handson.txt - Delightful JavaScript Testing Writing tests have high impact in application development The application will be stable and easy to
Jest - Handson.txt - Delightful JavaScript Testing Writing...
Delightful JavaScript TestingWriting tests have high impact in application development. The application will be stable and easy to maintain if the test results have few bugs.Jest is a JavaScript unit testing framework, maintained by Facebook that lets you define your unit tests.Features of JestMockingJest Allows to mock objects in test files.Can mock specific objects or turn on automatic mocking with ***automock***, which will mock every object.Snapshot TestingUI testing to become simplified as Jest can capture snapshots of React trees or other serializable values.Jest is Fast!Runs tests parallelly in processes to minimize test runtime.Runs previously failed tests first.Automatically finds tests related to changed files.Easy to set up JavaScript testing solution.Provides Test isolation i.e. no two tests will ever conflict with each other.Jest works well with other testing libraries (example Enzyme, Chai).Jest is used by Leading companies to test web applications, node.js services, mobile apps, and APIs.Installing JestInstall Jest using ***npm***:npm install jestOr via ***yarn***:yarn add jestKatacoda - A Playground for JestKatacoda is an interactive technical learning platform for software developers.Here you can use Katacoda Node.js v6 Playground to practice Jesting (Javascript Testing) by installing Jest in Katacoda Terminal.First Test Using JestCreate a sum.js file with a function that adds two numbers:function sum(a, b) {return a + b;}module.exports = sum;Create sum.test.js file. Let us get started by writing a test for the above function:const sum = require('./sum');test('addition: 1+2=3', () =>{expect(sum(1,2)).toBe(3);});Note: To create files, run the command touch <<filename>> in Katacoda terminal.Run the TestYou can run Jest from the terminal and finally, you get test results.Run all tests (default):jestRun only the tests that were stipulated with a pattern or filename:
jest sum.test --config=package.jsonJest runs all the files with .spec.js and .test.js extension in the current directory.Testing a To-do List ApplicationA simple To-do List Application has a lot of features to help you keep track of your daily commitments - Anywhere. Anytime.Let us test the javascript To-do List Application that has the following functions:addTaskupdateTaskcloseTaskdeleteTask***All hands-on across this course is based To-do list application***, to explore your understanding of the concepts and writing tests.You can refer the To-do List JavaScript functions in Codepen and can make use ofthat when you try to write tests on your own.-------------Jest is used to test _____________. JavaScriptJest works well with testing libraries like _________. AllJest can be installed using ________. npm install --save-dev jestJest is a JavaScript unit testing framework. TrueJest is maintained by _________ . Facebook-------------Introduction to MatchersJest utilizes matchers to test values in different ways. There are several matchers available and this section will introduce few of the most useful ones like,Common MatchersTruthinessNumbersStringsArraysExceptions etc.