Skip to content

Commit

Permalink
fix: catch env detect error
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Aug 26, 2021
1 parent 2cd356f commit 8c8edca
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/api/modules/utils_detectEnvironment.md
Expand Up @@ -14,8 +14,8 @@

### detectExecutionEnvironment

`Const` **detectExecutionEnvironment**(): [`ExecutionEnvironment`](../enums/utils_detectEnvironment.ExecutionEnvironment.md)
`Const` **detectExecutionEnvironment**(): `any`

#### Returns

[`ExecutionEnvironment`](../enums/utils_detectEnvironment.ExecutionEnvironment.md)
`any`
4 changes: 2 additions & 2 deletions src/utils/detectEnvironment.ts
Expand Up @@ -6,6 +6,6 @@ export enum ExecutionEnvironment {
export const detectExecutionEnvironment = () =>
(isNode() && ExecutionEnvironment.NODE) || (isBrowser() && ExecutionEnvironment.BROWSER);

const isNode = () => new Function("return this===global");
const isNode = new Function("try { return this === global } catch(e) { return false; }");

const isBrowser = () => new Function("return this===window");
const isBrowser = new Function("try { return this === window } catch(e) { return false; }");
@@ -1,7 +1,7 @@
import { detectExecutionEnvironment, ExecutionEnvironment } from "../../src/utils/detectEnvironment";

describe("Execution environment tests", () => {
it("tests are running in node env", () => {
expect(detectExecutionEnvironment()).toBe(ExecutionEnvironment.NODE);
it("tests are running in browser env", () => {
expect(detectExecutionEnvironment()).toBe(ExecutionEnvironment.BROWSER);
});
});

0 comments on commit 8c8edca

Please sign in to comment.