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...

This preview shows page 1 - 3 out of 13 pages.

Delightful JavaScript Testing Writing 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 Jest Mocking Jest Allows to mock objects in test files. Can mock specific objects or turn on automatic mocking with ***automock***, which will mock every object. Snapshot Testing UI 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 Jest Install Jest using ***npm***: npm install jest Or via ***yarn***: yarn add jest Katacoda - A Playground for Jest Katacoda 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 Jest Create 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 Test You can run Jest from the terminal and finally, you get test results. Run all tests (default): jest Run only the tests that were stipulated with a pattern or filename:
Image of page 1
jest sum.test --config=package.json Jest runs all the files with .spec.js and .test.js extension in the current directory. Testing a To-do List Application A 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: addTask updateTask closeTask deleteTask ***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 of that when you try to write tests on your own. ------------- Jest is used to test _____________. JavaScript Jest works well with testing libraries like _________. All Jest can be installed using ________. npm install --save-dev jest Jest is a JavaScript unit testing framework. True Jest is maintained by _________ . Facebook ------------- Introduction to Matchers Jest 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 Matchers Truthiness Numbers Strings Arrays Exceptions etc.
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 13 pages?

  • Summer '17
  • Mock object

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture