Skip to content

Commit

Permalink
verify if this is caused by Jest's mock implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gjf7 committed Oct 11, 2024
1 parent 4dcdc39 commit c4c1ddb
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions packages/neovim/src/attach/attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,22 @@ describe('Nvim API', () => {
expect(newLines).toEqual(['line1', 'line2']);
});

it('emits "disconnect" after quit', async () => {
const disconnectMock = jest.fn();
nvim.on('disconnect', disconnectMock);
nvim.quit();

const closePromise = new Promise(resolve => {
proc.on('close', resolve);
it('emits "disconnect" after quit', done => {
let called = false;
nvim.on('disconnect', () => {
called = true;
});

let timeout: NodeJS.Timeout;
nvim.quit();

await Promise.race([
closePromise.then(() => clearTimeout(timeout)),
new Promise((_, reject) => {
timeout = setTimeout(
() => reject(new Error('Timeout waiting for nvim to quit')),
5000
);
}),
]);
proc.on('close', () => {
expect(called).toBe(true);
done();
});

expect(disconnectMock).toHaveBeenCalledTimes(1);
}, 10000);
// Event doesn't actually emit when we quit nvim, but when the child process is killed
if (proc && proc.connected) {
proc.disconnect();
}
});
});

0 comments on commit c4c1ddb

Please sign in to comment.