Closed brandonmp closed 7 years ago
@brandonmp Try to use enzyme https://github.com/airbnb/enzyme
import React from 'react'
import {shallow} from 'enzyme'
import App from 'your-components/App'
it('renders without crashing', () => {
const wrapper = shallow (<App/>)
console.log(wrapper)
})
thanks @kradio3 . enzyme
coupled with this project seems to make jest snapshot tests work fine.
full example:
import React from 'react'
import MyThing from './index.js'
import 'react-mdl/extra/material.js'
import 'react-mdl/extra/material.css'
import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
it('renders correctly', () => {
const tree = shallow(
<MyThing
myProp={5}
/>
)
expect(toJson(tree)).toMatchSnapshot()
})
Trying-out MDL in a
create-react-app
i've ejected (that is, a vanilla webpack/babel react app)My test is pretty simple:
but at first it was throwing this:
I figured it was a problem w/
material.js
, so I added it:This, however, is throwing a diff't error:
Before I start pulling stuff out of
material.js
, I wanted to check-in here and see if there was an established solution to this problem.What's recommended way of testing w/ Jest?