Skip to content

Commit

Permalink
[Expressions] Fix expressions execution unit test to use fake timers …
Browse files Browse the repository at this point in the history
…for reliability (#99952) (#100016)
  • Loading branch information
dokmic authored May 13, 2021
1 parent 5f5401c commit 6554b9c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/plugins/expressions/common/execution/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,21 @@ describe('Execution', () => {
});

test('result is undefined until execution completes', async () => {
jest.useFakeTimers();
const execution = createExecution('sleep 10');
expect(execution.state.get().result).toBe(undefined);
execution.start(null).subscribe(jest.fn());
expect(execution.state.get().result).toBe(undefined);
await new Promise((r) => setTimeout(r, 1));

jest.advanceTimersByTime(1);
await new Promise(process.nextTick);
expect(execution.state.get().result).toBe(undefined);
await new Promise((r) => setTimeout(r, 11));

jest.advanceTimersByTime(10);
await new Promise(process.nextTick);
expect(execution.state.get().result).toBe(null);

jest.useRealTimers();
});

test('handles functions returning observables', () => {
Expand Down

0 comments on commit 6554b9c

Please sign in to comment.