2022-11-08 11:35:05 +08:00
# Testing
2022-10-31 22:41:24 +08:00
2022-11-08 11:35:05 +08:00
Testing is based on the [Jest ](https://jestjs.io/ ) testing framework. Also included are common React testing libraries such as [@testing-library/react ](https://testing-library.com/docs/react-testing-library/intro/ )
2022-10-31 22:41:24 +08:00
2022-11-08 11:35:05 +08:00
## Example
2022-10-31 22:41:24 +08:00
```tsx | pure
import { render } from '@testing-library/react';
import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { RouteSwitch } from '../RouteSwitch';
import { RouteSwitchProvider } from '../RouteSwitchProvider';
const Home = () => < h1 > Home< / h1 > ;
const About = () => < h1 > About< / h1 > ;
describe('route-switch', () => {
it('case 1', () => {
const App = () => {
return (
< RouteSwitchProvider components = {{ Home , About } } >
< MemoryRouter initialEntries = {['/']} >
< RouteSwitch
routes={[
{
type: 'route',
path: '/',
component: 'Home',
},
]}
/>
< / MemoryRouter >
< / RouteSwitchProvider >
);
};
const { container } = render(< App / > );
expect(container).toMatchSnapshot();
});
});
2022-11-08 11:35:05 +08:00
```