acme: async'ify
This commit is contained in:
38
src/test/promise-retry-test.js
Normal file
38
src/test/promise-retry-test.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/* jslint node:true */
|
||||
/* global it:false */
|
||||
/* global describe:false */
|
||||
|
||||
'use strict';
|
||||
|
||||
const expect = require('expect.js'),
|
||||
promiseRetry = require('../promise-retry.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('promiseRetry', function () {
|
||||
this.timeout(0);
|
||||
|
||||
it('normal return', async function () {
|
||||
const result = await promiseRetry({ times: 5, interval: 1000 }, async () => {
|
||||
return 42;
|
||||
});
|
||||
|
||||
expect(result).to.be(42);
|
||||
});
|
||||
|
||||
it('throws error', async function () {
|
||||
await safe(promiseRetry({ times: 5, interval: 1000 }, async () => {
|
||||
throw new Error('42');
|
||||
}));
|
||||
|
||||
expect(safe.error.message).to.be('42');
|
||||
});
|
||||
|
||||
it('3 tries', async function () {
|
||||
let tryCount = 0;
|
||||
const result = await promiseRetry({ times: 5, interval: 1000 }, async () => {
|
||||
if (++tryCount == 3) return 42; else throw new Error('42');
|
||||
});
|
||||
|
||||
expect(result).to.be(42);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user