我正在尝试测试我的SpringComponent。该组件将react-spring用于动画。运行测试时,出现以下错误:
“玩笑遇到了意外的令牌”。
如果我注释了Spring代码,则错误消失并且测试通过。
这是测试代码:
import React from "react";
import SpringComponent from "../components/SpringComponent";
test('renders without crashing', () => {
expect(true).toBeTruthy();
});
和SpringComponent代码:
import React from "react";
import {Spring} from "react-spring/renderprops-universal";
class SpringComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
content: this.props.content,
}
}
componentDidUpdate(prevProps) {
}
render() {
let content = this.state.content;
console.log("content: " + content);
return <div>
<Spring
from={{opacity: 0}}
to={{opacity: 1}}
>
{props => <div style={props}>
{content}
</div>}
</Spring>
</div>
}
}
export default SpringComponent;
我想知道如何测试此代码。我应该嘲笑什么吗?