Please enable JavaScript.
Coggle requires JavaScript to display documents.
React Testing - Coggle Diagram
React Testing
-
process
-
-
-
- create all possibility function will face for TDD,
example counter click
test('renders increment button', () => {}
test('renders counter display', () => {}
test('counter starts at 0', () => {}
test('counter increments when button is clicked', () => {}
-
-
-
-
-
-
You can use prop-types to document the intended types of properties passed to components. React (and potentially other libraries—see the checkPropTypes() reference below) will check props passed to your components against those definitions, and warn in development if they don’t match.
Manually check PropTypes-compatible proptypes, returning any errors instead of logging them to console.error.
This function is more suitable for checking propTypes in unit tests than mocking console.error, avoiding some serious problems with that approach.
Both Jest and Enzyme are specifically designed to test React applications, Jest can be used with any other Javascript app but Enzyme only works with React.
Jest can be used without Enzyme to render components and test with snapshots, Enzyme simply adds additional functionality.
Enzyme can be used without Jest, however Enzyme must be paired with another test runner if Jest is not used.
-
-
-
mock
Mock function
-
-
-
Notes
Do not destructure useState on import ,like import { useState } from "react"
-
-
-
-
-
-
API Testing
moxios
-
-
-
syntax
-
-
import moxios from 'moxios';
describe('moxios tests', () => {
beforeEach(() => {
moxios.install();
});
afterEach(() => {
moxios.uninstall();
});
....
}
-
This page assumes you’re using Jest as a test runner. If you use a different test runner, you may need to adjust the API, but the overall shape of the solution will likely be the same. Read more details on setting up a testing environment on the Testing Environments page.
-