1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
-
-
- const retry = require('../../bin/templates/cordova/lib/retry');
-
- describe('retry', () => {
- describe('retryPromise method', () => {
- let promiseFn;
-
- beforeEach(() => {
- promiseFn = jasmine.createSpy().and.returnValue(Promise.resolve());
- });
-
- it('should pass all extra arguments to the promise', () => {
- const args = ['test1', 'test2', 'test3'];
-
- retry.retryPromise(0, promiseFn, ...args);
- expect(promiseFn).toHaveBeenCalledWith(...args);
- });
-
- it('should retry the function up to specified number of times', () => {
- const attempts = 3;
- promiseFn.and.returnValue(Promise.reject());
-
- return retry.retryPromise(attempts, promiseFn).then(
- () => fail('Unexpectedly resolved'),
- () => expect(promiseFn).toHaveBeenCalledTimes(attempts)
- );
- });
-
- it('should not call the function again if it succeeds', () => {
- return retry.retryPromise(42, promiseFn).then(() => {
- expect(promiseFn).toHaveBeenCalledTimes(1);
- });
- });
- });
- });
|