From c741b098113a50fb6ddbb9de07e125218b0672ef Mon Sep 17 00:00:00 2001 From: Daniel Cassidy Date: Sat, 11 Apr 2020 03:46:26 +0100 Subject: [PATCH] jsdom: ResourceLoader#fetch may return null (#43669) According to the jsdom documentation, ResourceLoader#fetch may return null to indicate that the resource was intentionally not loaded. --- types/jsdom/index.d.ts | 2 +- types/jsdom/jsdom-tests.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/types/jsdom/index.d.ts b/types/jsdom/index.d.ts index 78d4004986..18a24addfe 100644 --- a/types/jsdom/index.d.ts +++ b/types/jsdom/index.d.ts @@ -62,7 +62,7 @@ declare module 'jsdom' { } class ResourceLoader { - fetch(url: string, options: FetchOptions): Promise; + fetch(url: string, options: FetchOptions): Promise | null; constructor(obj?: ResourceLoaderConstructorOptions); } diff --git a/types/jsdom/jsdom-tests.ts b/types/jsdom/jsdom-tests.ts index f9ef16b9ec..e5d4955364 100644 --- a/types/jsdom/jsdom-tests.ts +++ b/types/jsdom/jsdom-tests.ts @@ -190,6 +190,11 @@ function test_custom_resource_loader() { fetch(url: string, options: FetchOptions) { if (options.element) { console.log(`Element ${options.element.localName} is requesting the url ${url}`); + + if (options.element.localName === "iframe") { + console.log("Ignoring resource requested by iframe element"); + return null; + } } return super.fetch(url, options);