【发布时间】:2019-05-02 10:25:51
【问题描述】:
最近我将 styled-components 更新到 4.1.1 并且大部分组件测试都被破坏了。我只是创建一个哑组件来进行哑测试,看看它是否取决于其他测试是如何进行的,或者仅仅是样式组件的当前版本。
给出这个 Button 组件:
import styled from 'styled-components';
const Button = styled.button`
color: red;
`;
export default Button;
这里是相关测试:
import React from 'react';
import renderer from 'react-test-renderer';
import 'jest-styled-components';
import Button from './Button';
test('it works', () => {
const tree = renderer.create(<Button />).toJSON();
expect(tree).toMatchSnapshot();
});
输出是:
Invariant Violation: Unable to find node on an unmounted component.
可能是最新版本的 styled-components 和一些其他依赖导致的?
我没有在官方文档中找到任何东西。
【问题讨论】:
-
您使用的是哪个版本的
jest-styled-components? -
jest-styled-components@6.3.1
标签: reactjs unit-testing jestjs styled-components