import { hope } from '../index';
describe('hope promises', () => {
it('should call once', async () => {
const hopes = hope();
let callCount = 0;
const result = await hopes.once(async () => {
callCount++;
return 1;
});
const result2 = await hopes.once(async () => {
callCount++;
return 2;
});
const result3 = await hopes.once(async () => {
callCount++;
return 3;
});
expect(result).toBe(1);
expect(result2).toBe(1);
expect(result3).toBe(1);
expect(callCount).toBe(1);
});
it('should reject once', async () => {
const hopes = hope();
let callCount = 0;
hopes.once(async () => {
callCount++;
return await Promise.reject('buu');
});
let err = '';
try {
await hopes.once(async () => {
callCount++;
return 3;
});
} catch (e) {
err = e;
}
expect(callCount).toBe(1);
expect(err).toBe('buu');
});
it('should resolve with .resolve', async () => {
const hopes = hope();
hopes.resolve(1);
const result = await hopes.promise;
expect(result).toBe(1);
});
it('should reject with .reject', async () => {
const hopes = hope();
hopes.reject(1);
let err = '';
try {
await hopes.promise;
} catch (e) {
err = e;
}
expect(err).toBe(1);
});
});
``;
hoper
1.0.8 • Public • Published Readme
Keywords
nonePackage Sidebar
Install
npm i hoper
Weekly Downloads
73
Version
1.0.8
License
ISC
Unpacked Size
4.19 kB
Total Files
4