我有一个测试--它相对简单:
import {
fireEvent,
render,
} from '@testing-library/react';
// ...
it('Events should bubble when they aren\'t prevented from doing so', () => {
const parentF = jest.fn();
const childF = jest.fn();
const testDom = render(
<div onClick={parentF}>
<button onClick={childF} id="test-button">Test</button>
</div>
);
testDom.findByText('Test')
.then(element => {
fireEvent.click(element);
expect(parentF).toBeCalled();
expect(childF).toBeCalled();
});
});
// ...这是失败的,因为两者都没有被调用。我猜我在做一件愚蠢的事,但谁能告诉我那是什么?
发布于 2020-08-20 21:42:26
你有承诺,但jest不知道。试着退货:
return testDom.findByText('Test')
/* rest of the code */https://stackoverflow.com/questions/63505673
复制相似问题