smartpromise/test/test.both.ts

28 lines
834 B
TypeScript
Raw Normal View History

import { expect, tap } from '@push.rocks/tapbundle';
2023-04-04 18:22:57 +00:00
import * as smartpromise from '../ts/index.js';
2017-01-17 14:28:28 +00:00
2017-07-06 12:10:18 +00:00
tap.test('should return a Deferred for .defer()', async () => {
2019-10-01 16:06:29 +00:00
const myDeferred = smartpromise.defer();
2018-03-16 09:24:12 +00:00
myDeferred.resolve();
2023-04-04 18:22:57 +00:00
await myDeferred.promise;
2018-03-16 09:24:12 +00:00
});
2017-01-17 14:28:28 +00:00
2017-07-06 12:10:18 +00:00
tap.test('should let types flow through the Promise', async () => {
2019-10-01 16:06:29 +00:00
const myString = 'someString';
const myDeferred = smartpromise.defer<string>();
2018-03-16 09:24:12 +00:00
myDeferred.resolve(myString);
2023-04-04 18:22:57 +00:00
const result = await myDeferred.promise;
expect(result).toEqual('someString');
2018-03-16 09:24:12 +00:00
});
2017-01-28 15:37:54 +00:00
2017-07-06 12:10:18 +00:00
tap.test('should map callbacks', async () => {
2019-10-01 16:06:29 +00:00
const inputArray = ['hi', 'awesome'];
2020-10-15 18:14:53 +00:00
const myPromisified = async (myInput) => {
2019-03-26 11:07:12 +00:00
return myInput;
};
2023-04-04 18:22:57 +00:00
const result = await smartpromise.map(inputArray, myPromisified);
expect(result).toEqual(inputArray);
2018-03-16 09:24:12 +00:00
});
2017-07-06 12:10:18 +00:00
export default tap.start();