N
N
Ninja Mate2017-10-04 18:47:01
JavaScript
Ninja Mate, 2017-10-04 18:47:01

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)

The test is
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()
  })

  })

Mistake

__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

1 answer(s)
N
Negwereth, 2017-10-04
@victorzadorozhnyy

So is transform-class-properties worth it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question