abortsignal-polyfill.spec.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. describe('AbortSignal polyfills', function () {
  2. before(function () {
  3. // @ts-expect-error deleting a required method
  4. delete AbortSignal.any
  5. // @ts-expect-error deleting a required method
  6. delete AbortSignal.timeout
  7. // this polyfill provides the required methods
  8. cy.wrap(import('@/utils/abortsignal-polyfill'))
  9. })
  10. describe('AbortSignal.any', function () {
  11. it('aborts the new signal immediately if one of the signals is aborted already', function () {
  12. const controller1 = new AbortController()
  13. const controller2 = new AbortController()
  14. controller1.abort()
  15. const signal = AbortSignal.any([controller1.signal, controller2.signal])
  16. cy.wrap(signal.aborted).should('be.true')
  17. })
  18. it('aborts the new signal asynchronously if one of the signals is aborted later', function () {
  19. const controller1 = new AbortController()
  20. const controller2 = new AbortController()
  21. const signal = AbortSignal.any([controller1.signal, controller2.signal])
  22. controller1.abort()
  23. cy.wrap(signal.aborted).should('be.true')
  24. })
  25. })
  26. describe('AbortSignal.timeout', function () {
  27. it('aborts the signal after the timeout', function () {
  28. cy.clock().then(clock => {
  29. const signal = AbortSignal.timeout(1000)
  30. cy.wrap(signal.aborted).should('be.false')
  31. clock.tick(1000)
  32. cy.wrap(signal.aborted).should('be.true')
  33. })
  34. })
  35. })
  36. })