|
1 | | -import { elementUpdated, expect, fixture } from '@open-wc/testing'; |
| 1 | +import { elementUpdated, expect, fixture, waitUntil } from '@open-wc/testing'; |
2 | 2 | import { html, nothing } from 'lit'; |
3 | | -import { type SinonFakeTimers, spy, stub, useFakeTimers } from 'sinon'; |
| 3 | +import { spy, stub } from 'sinon'; |
4 | 4 | import type IgcIconButtonComponent from '../button/icon-button.js'; |
5 | 5 | import IgcChipComponent from '../chip/chip.js'; |
6 | 6 | import { enterKey } from '../common/controllers/key-bindings.js'; |
@@ -117,15 +117,9 @@ describe('Chat', () => { |
117 | 117 | ]; |
118 | 118 |
|
119 | 119 | let chat: IgcChatComponent; |
120 | | - let clock: SinonFakeTimers; |
121 | 120 |
|
122 | 121 | beforeEach(async () => { |
123 | 122 | chat = await fixture<IgcChatComponent>(html`<igc-chat></igc-chat>`); |
124 | | - clock = useFakeTimers({ toFake: ['setTimeout'] }); |
125 | | - }); |
126 | | - |
127 | | - afterEach(() => { |
128 | | - clock.restore(); |
129 | 123 | }); |
130 | 124 |
|
131 | 125 | describe('Initialization', () => { |
@@ -889,24 +883,21 @@ describe('Chat', () => { |
889 | 883 |
|
890 | 884 | it('emits igcTypingChange', async () => { |
891 | 885 | const eventSpy = spy(chat, 'emitEvent'); |
892 | | - const textArea = getChatDOM(chat).input.textarea!; |
| 886 | + const textArea = getChatDOM(chat).input.textarea; |
893 | 887 |
|
894 | | - simulateFocus(textArea); |
| 888 | + chat.options = { stopTypingDelay: 100 }; |
895 | 889 | simulateKeyboard(textArea, 'a'); |
896 | 890 | await elementUpdated(chat); |
897 | 891 |
|
898 | 892 | expect(eventSpy).calledWith('igcTypingChange'); |
899 | | - expect(eventSpy.getCall(1).args[1]?.detail).to.deep.equal({ |
900 | | - isTyping: true, |
901 | | - }); |
| 893 | + expect(eventSpy.firstCall.args[1]?.detail).to.eql({ isTyping: true }); |
902 | 894 |
|
903 | | - clock.tick(3001); |
904 | | - await elementUpdated(chat); |
| 895 | + eventSpy.resetHistory(); |
| 896 | + |
| 897 | + await waitUntil(() => eventSpy.calledWith('igcTypingChange')); |
905 | 898 |
|
906 | 899 | expect(eventSpy).calledWith('igcTypingChange'); |
907 | | - expect(eventSpy.getCall(2).args[1]?.detail).to.deep.equal({ |
908 | | - isTyping: false, |
909 | | - }); |
| 900 | + expect(eventSpy.firstCall.args[1]?.detail).to.eql({ isTyping: false }); |
910 | 901 | }); |
911 | 902 |
|
912 | 903 | it('emits igcInputFocus', async () => { |
|
0 commit comments