react-router-testing

0.2.1 • Public • Published

React router testing

npm version

author: Aral Roca aral-rg@hotmail.com


The idea of this library is to use together with react-testing-library.

Is an utility to test react-router things.

Install

  • npm install react-router-testing --save

Required

  • react-testing-library -> ^5.4.4
  • react -> ^16.7.0
  • react-dom -> ^16.7.0
  • react-router-dom -> ^4.3.1

Usage

import React from 'react'
import { renderWithRouter } from 'react-router-testing'
import LinkButton from './LinkButton'
 
describe('LinkButton Component', () => {
  test('LinkButton is disabled meanwhile is loading', () => {
    const text = 'Some text'
    const { getByText, rerender } = renderWithRouter(
      <LinkButton text={text} />,
    )
    const LinkButtonNode = getByText(text)
 
    expect(LinkButtonNode.disabled).toBe(false)
 
    // update loading to true
    rerender(
      <LinkButton text={text} loading />,
    )
 
    expect(LinkButtonNode.disabled).toBe(true)
 
    // update loading to false
    rerender(
      <LinkButton text={text} loading={false} />,
    )
 
    expect(LinkButtonNode.disabled).toBe(false)
  })
})

/react-router-testing/

    Package Sidebar

    Install

    npm i react-router-testing

    Weekly Downloads

    1

    Version

    0.2.1

    License

    MIT

    Unpacked Size

    4.76 kB

    Total Files

    4

    Last publish

    Collaborators

    • aralroca