Replies: 2 comments 3 replies
-
I usually write a test component that uses Note that you don't have to write a test that waits for 3 seconds: you can use fake timers to "advance the time" by 3 seconds, and have a test that runs instantly. Check https://jestjs.io/docs/timer-mocks if you sue Jest. |
Beta Was this translation helpful? Give feedback.
-
I have tried it according to your suggestion, and it seems to have solved my problem. I have posted the code here, and I hope to get advice if there is any improvement. I felt very happy when I saw the green pass displayed on the terminal. Thank you very much for your help and guidance. jest.useFakeTimers();
describe('ChildEmit', () => {
it('emit', () => {
const wrapper = mount(ChildEmit, {
props: {
onCrossOpen: jest.fn(),
time: 3000
}
});
const dom = wrapper.findComponent(ChildEmit);
expect(dom.props()['onCrossOpen']).not.toBeCalled();
expect(dom.props()['onCrossOpen']).toHaveBeenCalledTimes(0);
jest.runAllTimers()
expect(dom.props()['onCrossOpen']).toBeCalled();
expect(dom.props()['onCrossOpen']).toHaveBeenCalledTimes(1)
});
}) |
Beta Was this translation helpful? Give feedback.
-
The current situation is that instead of using
emit
, I am usingprops.OnCrossOpen?.()
to trigger. I want to know how to write test cases.The following code:
I know it is written in the
emit
wayWhat should I do if I use
props.onCrossOpen()
? I need your help, Thank you very much!Beta Was this translation helpful? Give feedback.
All reactions