我有一个功能组件getCurrencyRate:
export const getCurrencyRate = (value1, value2) => {
return (
<span>
The rate is:
<Sum currency={value2}>
{value1}
</Sum>
</span>
);
};
它使用来自另一个文件的Sum组件:
export const Sum = (props) => {
const { children, currency } = props;
return (
<span>
{children} {currency}
</span>
);
};
我想测试getCurrencyRate组件。我是这样的:
it('should return correct value', () => {
const correctResult = <span>The rate is: <Sum currency='USD'>500</Sum></span>;
const result = shallow(getCurrencyRate(500, 'USD'));
expect(result.text()).toEqual(correctResult);
});
并得到一个错误:
Expected value to equal:
<span>The rate is: <Sum currency='USD'>500</Sum></span>an>
Received:
"The rate is: <Sum />"
我该如何解决?