Skip to content

Commit

Permalink
[Test] more FakeAsync unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bistard committed Aug 21, 2023
1 parent c3f1dd2 commit 3c7016f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
13 changes: 10 additions & 3 deletions test/utils/fakeAsync.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as assert from 'assert';
import { delayFor } from 'src/base/common/util/async';
import { FakeAsync, IFakeAsyncOptions } from 'test/utils/fakeAsync';
import { FakeConsole } from 'test/utils/fakeConsole';

suite.only('FakeAsync-test', () => {
suite('FakeAsync-test', () => {

test('fake the function execution when fake timers are enabled', async () => {
let fakeElapsedTime: number = undefined!;
Expand Down Expand Up @@ -58,10 +59,16 @@ suite.only('FakeAsync-test', () => {
});

test('run function with default error handling', async () => {
let errorMessage: any;
FakeConsole.enable({
onLog: (message) => errorMessage = message
});

const errorFunction = () => { throw new Error('Test error'); };
let caughtError: any;
await FakeAsync.run(errorFunction);
assert.strictEqual(caughtError.message, 'Test error');
assert.strictEqual(errorMessage.message, 'Test error');

FakeConsole.disable();
});

test('run function with custom error handling', async () => {
Expand Down
8 changes: 5 additions & 3 deletions test/utils/fakeConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export namespace FakeConsole {
}

// callback
options.onLog(message);
options.onLog(message, ...optionalParams);
};
}

Expand All @@ -41,9 +41,11 @@ export interface IFakeConsoleOptions {

/**
* Callback to recieve the log message.
* @param message the log message.
* @param message The primary message to log. This could be any data type.
* @param optionalParams Additional parameters that may accompany the
* primary message, often used for formatting.
*/
readonly onLog?: (message: string) => void;
readonly onLog?: (message: any, ...optionalParams: any[]) => void;
}

const trueConsole = {
Expand Down

0 comments on commit 3c7016f

Please sign in to comment.