Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

retry.spec.js 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. const retry = require('../../bin/templates/cordova/lib/retry');
  18. describe('retry', () => {
  19. describe('retryPromise method', () => {
  20. let promiseFn;
  21. beforeEach(() => {
  22. promiseFn = jasmine.createSpy().and.returnValue(Promise.resolve());
  23. });
  24. it('should pass all extra arguments to the promise', () => {
  25. const args = ['test1', 'test2', 'test3'];
  26. retry.retryPromise(0, promiseFn, ...args);
  27. expect(promiseFn).toHaveBeenCalledWith(...args);
  28. });
  29. it('should retry the function up to specified number of times', () => {
  30. const attempts = 3;
  31. promiseFn.and.returnValue(Promise.reject());
  32. return retry.retryPromise(attempts, promiseFn).then(
  33. () => fail('Unexpectedly resolved'),
  34. () => expect(promiseFn).toHaveBeenCalledTimes(attempts)
  35. );
  36. });
  37. it('should not call the function again if it succeeds', () => {
  38. return retry.retryPromise(42, promiseFn).then(() => {
  39. expect(promiseFn).toHaveBeenCalledTimes(1);
  40. });
  41. });
  42. });
  43. });