scroll/src/bun/test_base.ts

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-03 11:59:58 -04:00
/**
* Adapt the bun test interface to the shared testing interface
*/
import { describe, expect, test } from 'bun:test';
2023-11-29 16:09:58 -05:00
import { ITestBase } from '../common/types.ts';
2023-11-03 11:59:58 -04:00
export function testSuite(testObj: any) {
Object.keys(testObj).forEach((group) => {
describe(group, () => {
const groupObj = testObj[group];
Object.keys(groupObj).forEach((testName) => {
test(testName, groupObj[testName]);
});
});
});
2023-11-03 11:59:58 -04:00
}
const BunTestBase: ITestBase = {
assertEquals: (actual: unknown, expected: unknown) =>
expect(actual).toEqual(expected),
assertExists: (actual: unknown) => expect(actual).toBeDefined(),
assertFalse: (actual: boolean) => expect(actual).toBe(false),
assertInstanceOf: (actual: unknown, expectedType: any) =>
expect(actual).toBeInstanceOf(expectedType),
assertNotEquals: (actual: unknown, expected: unknown) =>
expect(actual).not.toBe(expected),
2023-11-30 16:14:52 -05:00
assertNull: (actual: unknown) => expect(actual).toBeNull(),
assertStrictEquals: (actual: unknown, expected: unknown) =>
expect(actual).toBe(expected),
assertTrue: (actual: boolean) => expect(actual).toBe(true),
testSuite,
};
export default BunTestBase;