【发布时间】:2020-08-20 21:49:57
【问题描述】:
我有一个测试——比较简单:
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();
});
});
// ...
这失败了,说两者都没有被调用。我猜我在做一些愚蠢的事情,但有人能告诉我这是什么吗?
【问题讨论】:
-
走同步路线,测试通过 - 例如 fireEvent.click(testDom.getByText('Test'))
标签: javascript reactjs jestjs react-testing-library