Answer the question
In order to leave comments, you need to log in
How to test such a component in Jest?
There is a problem how to test such a component.
import React from 'react'
// rowMenuComposer мне не нужно тестировать, но как без него запустить не понимаю
import rowMenuComposer from '../../lib/reactv-navigation/components/RowMenu'
import StationCard from '../StationCard'
import './StationList.scss'
export const StationList = ({menuItems, isFocused, menu: { index }, zip}) => {
return (
<div className='StationList'>
<div style={{left: index * -320}}>
<p className='h3'>Stations near {zip}</p>
{menuItems.map((station, idx) => (
<StationCard key={`rec:${station.attributes.guid}`}
{...station.attributes}
logo={station.logo}
focused={isFocused(idx)} />
))}
</div>
</div>
)
}
// вот это не хочу тестировать
export default rowMenuComposer(StationList)
import React from 'react'
import { shallow } from 'enzyme'
import StationCard from './../src/components/StationCard/StationCard'
// StationList правильно делаю импорт?
import {StationList} from './../src/components/StationList/StationList'
import renderer from 'react-test-renderer'
describe('Test Station Router', () => {
// проходим
it('renders correctly StationCard', () => {
const tree = renderer.create(
<StationCard brand='Name' logo='logo' focused />
).toJSON()
expect(tree).toMatchSnapshot()
})
// не проходим выдает ошибку с указанием на место в файле из StationList default import rowMenuComposer
// по идеи его мне вообще не нужно импортировать
it('renders correctly', () => {
const menuItems = [{...}]
const tree = renderer.create(
<StationList menuItems={menuItems}
isFocused={true}
index={0}
zip="11111"
/>
).toJSON()
expect(tree).toMatchSnapshot()
})
})
__tests__/Station.test.js
● Test suite failed to run
/Users/ninjamate/Documents/projects/NPROne-X1/src/lib/reactv-navigation/components/RowMenu.js: Unexpected token (14:24)
12 | const RowMenuComposer = (InnerComponent, direction = 'horizontal') => {
13 | class RowMenu extends React.Component {
> 14 | static contextTypes = {
| ^
15 | mid: PropTypes.string,
16 | getMenuId: PropTypes.func
17 | }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question