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