【发布时间】:2021-03-07 17:00:45
【问题描述】:
我正在尝试将 jest 与样式化组件一起使用来测试组件的样式,但我遇到了错误:
Syntax error parsing expected css: missing '}' here
Failing css:
[object Object]
我的组件是一个带有 styled-components 的简单链接:
import styled from 'styled-components'
export const Link = styled.a`
color: #fff;
`
我的测试:
describe('Link', () => {
it('should display color on the link', () => {
render(<Link href="/x">Test</Link>)
}
expect(screen.getByRole('link', { name: /test/i })).toHaveStyle({ color: '#fff' })
}
我正在运行 npm react-scripts 测试。
我尝试导入“jest-styled-components”和“@testing-library/jest-dom”
【问题讨论】:
标签: reactjs jestjs styled-components