我正在尝试对下面的组件进行单元测试,但是运行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()
})
})
任何想法我该怎么解决?