0.0.0 • Published 3 years ago

react-router-redux-test v0.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

react-router-redux-test

This library replace @testing-library/react render with a new render wrapper to use components with router and redux and reexport all from @testing-library/react

Examples

Sample component using react-router-dom Link, usually this component throw an error, because depends on the react-router initialize.

import React from 'react';
import {Link} from 'react-router-dom';

const MyComponent = props => <Link data-testid='MyComponent' to={props.to}>{props.children}</Link>;

export default MyComponent;

The test sample

import React from 'react';
import {cleanup, render, screen} from 'react-router-redux-test';
import MyComponent from './MyComponent';

afterEach(cleanup);

describe('<MyComponent /> spec', () => {
  it('should render my component', function () {
    render(<MyComponent to='/'>Boo!</MyComponent>);
    
    expect(screen.getByTestId('MyComponent')).toHaveTextContent('Boo!');
  });
});