smartexpect/test/test.ts
2022-07-24 12:45:29 +02:00

48 lines
1.4 KiB
TypeScript

import { tap } from '@pushrocks/tapbundle';
import * as smartexpect from '../ts/index.js';
tap.test('sync tests', async () => {
smartexpect.expect('hello').toBeTypeofString();
smartexpect.expect(1).not.toBeTypeofString();
smartexpect.expect(true).toBeTypeofBoolean();
smartexpect.expect(true).not.toBeTypeofNumber();
});
tap.test('async tests', async (toolsArg) => {
const deferred = toolsArg.defer();
toolsArg.delayFor(4000).then(() => {
deferred.resolve('hello');
});
await smartexpect.expectAsync(deferred.promise).timeout(5000).toBeTypeofString();
await smartexpect.expectAsync(deferred.promise).not.toBeTypeofBoolean();
});
tap.test('should check equality', async () => {
smartexpect.expect('hithere').toEqual('hithere');
smartexpect.expect('hithere').not.toEqual('hithere2');
});
tap.test('should correctly state property presence', async () => {
const testObject = {
aprop: 'hello',
};
smartexpect.expect(testObject).toHaveProperty('aprop');
smartexpect.expect(testObject).not.toHaveProperty('aprop2');
});
tap.test('should be greater than', async () => {
smartexpect.expect(4).toBeGreaterThan(3);
smartexpect.expect(4).toBeLessThan(5);
});
tap.test('should correctly determine toContain', async () => {
const hello = {
socool: 'yes',
};
const testArray = [hello];
smartexpect.expect(testArray).toContain(hello);
});
tap.start();