0.0.1 • Published 6 years ago

karma-enzyme-react-15 v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Karma-Enzyme automatically includes pre-configured Enzyme methods in Karma test suite, enabling you to easily configure Enzyme 3 with multiple versions of React.

Requirements

This package requires that your Karma test suite is being run in Webpack.

Configuration Options

There is a npm package for each available enzyme-react adapter:

karma-enzyme packageEnzyme Adapter PackageReact semver compatibility
karma-enzyme-react-16enzyme-adapter-react-16^16.0.0
karma-enzyme-react-15enzyme-adapter-react-15^15.5.0
karma-enzyme-react-15.4enzyme-adapter-react-15.415.0.0-0 - 15.4.x
karma-enzyme-react-14enzyme-adapter-react-14^0.14.0
karma-enzyme-react-13enzyme-adapter-react-13^0.13.0

Installation

* Example uses karma-enzyme-react-16 as an example. Use the correct package for your desired configuration.

Install it with npm install karma-enzyme-react-16 --save-dev.

Add enzyme-react-16 to the frameworks key and karma-enzyme-react-16 to the plugins key in your Karma configuration:

frameworks = ['enzyme-react-16'];
plugins = ['karma-enzyme-react-16'];

Usage

Enzyme will be configured using the appropriate adapter and each of the different Enzyme methods are available in the tests:

import React from 'react'
import MyComponent from 'path/to/MyComponent'

describe('MyComponent', () => {
  it('renders', () => {
    shallow(<MyComponent />)
    mount(<MyComponent />)
    render(<MyComponent />)
  })
})

The entire enzyme api is also available as Enzyme:

import React from 'react'
import MyComponent from 'path/to/MyComponent'

describe('MyComponent', () => {
  it('renders', () => {
    Enzyme.shallow(<MyComponent />)
    Enzyme.mount(<MyComponent />)
    Enzyme.render(<MyComponent />)
  })
})

License

The MIT License (MIT)