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.
This commit is contained in:
Daniel Cassidy
2020-04-10 19:46:26 -07:00
committed by GitHub
parent 3788b96caa
commit c741b09811
2 changed files with 6 additions and 1 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ declare module 'jsdom' {
}
class ResourceLoader {
fetch(url: string, options: FetchOptions): Promise<Buffer>;
fetch(url: string, options: FetchOptions): Promise<Buffer> | null;
constructor(obj?: ResourceLoaderConstructorOptions);
}
+5
View File
@@ -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);