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