@johngw/react-component-mock
TypeScript icon, indicating that this package has built-in type declarations

2.1.2 • Public • Published

react-component-mock

A simple way to mock react components when testing.

The module creates a new component which will render a string representation of the component and it's props

Install

npm i -D @johngw/react-component-mock

When working on the source code:

npm i
npx husky install

Usage (Jest)

// App.tsx

import React from 'react'
import Hello from './Hello'

export default function App() {
  return <Hello name="World" />
}
// __mocks__/Hello.tsx

import reactComponentMock from '@johngw/react-component-mock'

export default reactComponentMock('Hello')
// __tests__/App.test.tsx

import React from 'react'
import { render } from '@testing-library/react'
import App from '../App'

jest.mock('../Hello')

test('App', () => {
  const { container } = render(<App />)
  expect(container).toMatchInlineSnapshot(`
    {Hello name=\`World\`}
  `)
})

Readme

Keywords

none

Package Sidebar

Install

npm i @johngw/react-component-mock

Weekly Downloads

8

Version

2.1.2

License

MIT

Unpacked Size

70.9 kB

Total Files

18

Last publish

Collaborators

  • johngeorgewright