我需要测试useEffect后的状态更改
FooView.jsx文件:
const [total, setTotal] = useState(0);
useEffect(() => {
calculatedTotal = calculateTotal(page.paymentSchedule);
setTotal(calculatedTotal);
}, [
page.paymentSchedule,
]);
FooView-测试.jsx:
describe('...', () => {
const paymentSchedule = [
{
count: 2,
amount: 100,
},
{
count: 3,
amount: 200,
}
];
it('should update total when the payment schedule changes', () => {
const container = mount(<FooView />);
container.find('FooView').prop('paymentSchedule')(paymentSchedule);
// what to do next
});
}
我使用了Jest和Enzyme,如何测试得到的状态值?
1条答案
按热度按时间vcirk6k61#
您需要设置另一个UseEffect,如下所示:
这样,通过
setTotal
对total
所做的每一次更改都将返回到控制台中