Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用已设置样式的组件设置导入组件的样式会导致Jest崩溃_Javascript_Reactjs_Jestjs_Enzyme_Styled Components - Fatal编程技术网

Javascript 使用已设置样式的组件设置导入组件的样式会导致Jest崩溃

Javascript 使用已设置样式的组件设置导入组件的样式会导致Jest崩溃,javascript,reactjs,jestjs,enzyme,styled-components,Javascript,Reactjs,Jestjs,Enzyme,Styled Components,当我导入组件(react slider)并通过已设置样式的组件设置样式时,Jest崩溃 其代码如下所示: 我的Component.styles.js文件: import styled, { css } from 'styled-components' import ReactSlider from 'react-slider' const StyledReactSlider = styled(ReactSlider)` ...CSS here ` 我的组成部分如下: import React

当我导入组件(
react slider
)并通过已设置样式的组件设置样式时,Jest崩溃

其代码如下所示:

我的
Component.styles.js
文件:

import styled, { css } from 'styled-components'
import ReactSlider from 'react-slider'

const StyledReactSlider = styled(ReactSlider)`
...CSS here
`
我的组成部分如下:

import React from 'react'
import PropTypes from 'prop-types'

import * as Styled from './Component.styles'

...Lots of code

<Styled.StyledReactSlider
barClassName={'slider-bar'}
handleClassName={'slider-handle'}
withBars
max={max}
value={value}
onChange={onChange}
/>

...Lots more code
从“React”导入React
从“道具类型”导入道具类型
从“./Component.styles”导入*作为样式
…大量代码
…更多的代码
最后,我的非常简单的测试文件:

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

import 'jest-styled-components'

import MyComponent from './MyComponent'

describe('Component Tests ', () => {
  it(`should render the <MyComponent /> default correctly`, () => {
    const component = mount(<MyComponent />)
    expect(component).toMatchSnapshot()
    component.unmount()
  })
})
从“React”导入React
从“酶”导入{mount}
导入“jest样式的组件”
从“/MyComponent”导入MyComponent
描述('组件测试',()=>{
它(`应该正确地呈现默认值',()=>{
常量组件=挂载()
expect(component.toMatchSnapshot())
component.unmount()
})
})
由此产生的结果是一个大错误,看起来节点内存不足(JavaScript堆内存不足消息),然后终端挂起

这是使用
react slider 0.11.2
样式化组件4.3.1
jest 24.8.0

注意:如果我不将组件导入样式文件,测试运行正常,因此我认为导入的组件样式一定出了问题