generic-react-test

1.0.16 • Public • Published

generic-react-test

Install


  npm install --save-dev generic-react-test

Usage


  // *.test.js
  import {commonTest} from 'generic-react-test'
  import {Component} from '[LOCATION_TO_YOUR_COMPONENT]'
  import {apiService} from '[LOCATION_TO_YOUR_API_SERVICE]'

  // Testing shallow render component using enzyme API
  commonTests.checkShallow({
    component: , // Pass imported Component
    componentName: 'Component Name' // Mention component name
  });

  // Testing component mount component using enzyme API
  commonTests.checkMount({
    component: , // Pass imported Component
    componentName: 'Component Name' // Mention component name
  });

  // Mock API calls using nock js
  commonTests.checkAPI({
    baseUrl: http://localhost:5000, // API base url
    subUrl: "/api", // API subUrl
    request: {'requestKey': 'requestValue'}, // sample json request to be sent to API
    response: {'responseKey': 'responseValue'}, // sample json response to be expected from API
    service: apiService, // Promise which makes the API call to the server
    keyToCompare: ["responseKey"], // key which holds the value to be compared with api response
    componentName: 'Component Name' // Mention component name
  });

Test Report


PASS *.test.js (6.137s)
  Common tests for renders
    √ Component Name page renders

Readme

Keywords

none

Package Sidebar

Install

npm i generic-react-test

Weekly Downloads

0

Version

1.0.16

License

ISC

Unpacked Size

9.24 kB

Total Files

5

Last publish

Collaborators

  • surajrl