Giter VIP home page Giter VIP logo

unit_test_react_native's Introduction

Unit Testing in React Native:

Unit Testing in React Native using Jest

Unit Testing with Test Report and Code Coverage Report Generation

Check and Add Jest :

> When we create a react-native project, by default jest is added .

> To check this please go to package.json and check "test": “jest" inside “scripts”. And “jest" dependency will be there. If it is not present add jest using command “npm install --save-dev jest ” .

Run all Test Files :

> Run the command “npm run test”

> All the test case results will be shown in terminal.

Run a particular Test File :

> Run the Command “npx jest testfilename”

For e.g=> npx jest App-test.js

Updating Snapshots :

> npx jest --updateSnapshot

Test Report Generation :

> To Generate Test Report we need to add jest-html-reporter

> To add this run command “npm install --save-dev jest-html-reporter” And add “reporters” inside “jest” dependency in package.json file .

> Run the command “npm run test” and test report will be generated as a file name called “test-report.html” in the root of the project.

Code Coverage Rreport Generation :

> To Generate Code Coverage report add the below code inside the “jest” dependency .

"collectCoverage": true,

"coverageReporters": [ "json", "html" ]

> To Generate Code Coverage Report of all TestFiles run command “npx jest --coverage”

> It will generate a folder called coverage in root of the project and inside it “index.html” contains the Code Coverage report.

To generate a specific testfile code coverage report :

> npx jest --coverage -- testfilename

Test Report Code Coverage Report

unit_test_react_native's People

Contributors

ashu777 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.