whatwg-fetch.js 892 B

123456789101112131415161718192021222324252627
  1. const { AbortController } = require("../index.js");
  2. const { fetch } = require("whatwg-fetch");
  3. describe("node-fetch", function () {
  4. it("should throw exception if aborted during the request", async function () {
  5. expect.assertions(1);
  6. try {
  7. const controller = new AbortController();
  8. const signal = controller.signal;
  9. setTimeout(() => controller.abort(), 5);
  10. await fetch("https://www.google.com/", { signal });
  11. } catch (err) {
  12. expect(err.name).toBe("AbortError");
  13. }
  14. });
  15. it("should throw exception if passed an already aborted signal", async function () {
  16. expect.assertions(1);
  17. try {
  18. const controller = new AbortController();
  19. const signal = controller.signal;
  20. controller.abort();
  21. await fetch("https://www.google.com/", { signal });
  22. } catch (err) {
  23. expect(err.name).toBe("AbortError");
  24. }
  25. });
  26. });