具有流量类型的反应组分的单元测试

时间:2019-08-28 19:59:23

标签: javascript reactjs jestjs enzyme flowtype

我正在尝试对下面的组件进行单元测试,但是运行yarn run test

后收到以下警告
> Warning: React.createElement: type is invalid -- expected a string
> (for built-in components) or a class/function (for composite
> components) b ut got: object.

我在这里使用带有Flow和Jest和Enzyme作为测试框架的React 16.8

我要测试该组件

// @flow

import React from 'react'
import Button from './styled'

export type Props = {
  +children: React$Node
}

const ButtonDark = ({ children }: Props) => (
  <>
    <Button>{children}</Button>
  </>
)

export default ButtonDark

使用此测试文件:

import React from 'react'
import { shallow } from 'enzyme'

import ButtonDark from '.'

jest.mock('./styled', () => ({
    Button: 'Button'
}))

describe('ButtonDark', () => {
  it('renders', () => {

    const wrapper = shallow(<ButtonDark>{'some children'}</ButtonDark>)

    expect(wrapper).toMatchSnapshot()
  })
})

任何想法我该怎么解决?

0 个答案:

没有答案