-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUnitTest.ts
More file actions
38 lines (32 loc) · 1.24 KB
/
UnitTest.ts
File metadata and controls
38 lines (32 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { Context, Failure, TestError, TestLabel, TestLogs } from '@ephox/bedrock-common';
import { describe, it } from './Bdd';
type TestLogs = TestLogs.TestLogs;
type TestError = TestError.TestError;
export type SuccessCallback = () => void;
export type TestThrowable = TestLabel | TestError;
export type FailureCallback = (error: TestThrowable, logs?: TestLogs) => void;
/** An asynchronous test with callbacks. */
export const asyncTest = (name: string, test: (this: Context, success: SuccessCallback, failure: FailureCallback) => void): void => {
describe('old-style test', () => {
it(name, function (done) {
test.call(this, () => done(), ((err, logs) => {
const r = Failure.prepFailure(err, logs);
done(r);
}));
});
});
};
/** Migrate to asyncTest */
export const asynctest = asyncTest;
/** A synchronous test that fails if an exception is thrown */
export const test = (name: string, test: (this: Context) => void): void => {
describe('old-style test', () => {
it(name, test);
});
};
/** Tests an async function (function that returns a Promise). */
export const promiseTest = (name: string, test: (this: Context) => Promise<void>): void => {
describe('old-style test', () => {
it(name, test);
});
};