我有一个测试-比较简单:
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();
});
});
// ...
这无法说明没有人被呼叫。我猜我在做一些愚蠢的事情,但是有人可以告诉我这是什么吗?
答案 0 :(得分:1)
您有一个承诺,但开玩笑并不知道。尝试返回它:
return testDom.findByText('Test')
/* rest of the code */