Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Commit

Permalink
Revert userAgent bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ianschmitz committed Nov 29, 2019
1 parent d3b1c51 commit f891deb
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 15 deletions.
9 changes: 0 additions & 9 deletions src/__tests__/index.test.ts
Expand Up @@ -29,13 +29,4 @@ describe("JSDomEnvironment", () => {

expect(instance!.global.location.href).toBe(href);
});

it("sets resource loader options", () => {
const userAgent = "some agent";
instance = new JSDomEnvironment({
testEnvironmentOptions: { userAgent },
} as any);

expect(instance!.global.navigator.userAgent).toBe(userAgent);
});
});
7 changes: 1 addition & 6 deletions src/index.ts
Expand Up @@ -4,7 +4,7 @@ import { installCommonGlobals } from "jest-util";
import { ModuleMocker } from "jest-mock";
import { JestFakeTimers as FakeTimers } from "@jest/fake-timers";
import { EnvironmentContext, JestEnvironment } from "@jest/environment";
import { JSDOM, ResourceLoader, VirtualConsole } from "jsdom";
import { JSDOM, VirtualConsole } from "jsdom";

// The `Window` interface does not have an `Error.stackTraceLimit` property, but
// `JSDOMEnvironment` assumes it is there.
Expand All @@ -23,16 +23,11 @@ class JSDOMEnvironment implements JestEnvironment {
moduleMocker: ModuleMocker | null;

constructor(config: Config.ProjectConfig, options: EnvironmentContext = {}) {
// This handles advanced configurations like `userAgent`
// https://github.com/jsdom/jsdom#advanced-configuration
const resourceLoader = new ResourceLoader(config.testEnvironmentOptions);

this.dom = new JSDOM("<!DOCTYPE html>", {
pretendToBeVisual: true,
runScripts: "dangerously",
url: config.testURL,
virtualConsole: new VirtualConsole().sendTo(options.console || console),
resources: resourceLoader,
...config.testEnvironmentOptions,
});
const global = (this.global = this.dom.window.document.defaultView as Win);
Expand Down

0 comments on commit f891deb

Please sign in to comment.