3.0.0 • Published 5 years ago

enzyme-theme-utils v3.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Enzyme Theme Utils

npm install enzyme-theme-utils

Motivation

Testing React components that need to be wrapped in a ThemeProvider is a pain in the butt. So after lots of trial-and-error programming I created this module to rectify this. Essentially what it does is renders the ThemeProvider and it's children inside a wrapper. Then it adds context to the wrapped ThemeProvider. Then it extracts the children and adds the context from the ThemeProvider to the child and mounts it.

Usage

shallowWithTheme

import React from 'react'
import PropTypes from 'prop-types'
import { shallowWithTheme } from 'enzyme-theme-utils'

const someTheme = {
  colors: {
    red: 'red',
    yellow: 'yellow'
  }
}

describe('some themed component', () => {

  it('can be shallow rendered', () => {
    const test = shallowWithTheme(
      <SomeComponent/>,
      someTheme
    )

    // Assertions

  })
})

mountWithTheme

import React from 'react'
import PropTypes from 'prop-types'
import { mountWithTheme } from 'enzyme-theme-utils'

const someTheme = {
  colors: {
    red: 'red',
    yellow: 'yellow'
  }
}

describe('some themed component', () => {

  it('can be mounted', () => {
    const test = mountWithTheme(
      <SomeComponent/>,
      someTheme
    )

    // Assertions

  })
})

MIT License

3.0.0

5 years ago

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0-1

6 years ago

1.0.0

6 years ago