diff --git a/package-lock.json b/package-lock.json index 2e60466..af8ed32 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@nosto/nosto-react", - "version": "1.0.0", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@nosto/nosto-react", - "version": "1.0.0", + "version": "2.0.0", "license": "ISC", "devDependencies": { "@testing-library/jest-dom": "^5.16.5", diff --git a/package.json b/package.json index 3aaab1f..96bd695 100644 --- a/package.json +++ b/package.json @@ -73,10 +73,8 @@ "homepage": "https://github.com/Nosto/nosto-react#readme", "jest": { "preset": "ts-jest", - "testEnvironment": "jsdom", - "testEnvironmentOptions": { - "resources": "usable", - "runScripts": "dangerously" - } + "setupFiles": [ + "./spec/setup.js" + ] } } diff --git a/spec/setup.js b/spec/setup.js new file mode 100644 index 0000000..9ef4acb --- /dev/null +++ b/spec/setup.js @@ -0,0 +1,14 @@ +const { JSDOM } = require("jsdom") + +const { window } = new JSDOM("", { + url: "http://localhost", + resources: "usable", + runScripts: "dangerously" }) +global.window = window +global.location = window.location +global.document = window.document +global.localStorage = window.localStorage +global.navigator = window.navigator + +// test mode flag +global.window.nostoReactTest = true \ No newline at end of file diff --git a/src/components/NostoProvider.tsx b/src/components/NostoProvider.tsx index e9a2347..19ebc27 100644 --- a/src/components/NostoProvider.tsx +++ b/src/components/NostoProvider.tsx @@ -95,7 +95,7 @@ export default function NostoProvider(props: NostoProviderProps) { script.setAttribute("nosto-client-script", "") script.onload = () => { - if (typeof jest !== "undefined") { + if ("nostoReactTest" in window) { window.nosto?.reload({ site: "localhost", }) @@ -136,7 +136,7 @@ export default function NostoProvider(props: NostoProviderProps) { script.setAttribute("nosto-market-id", String(shopifyMarkets?.marketId)) script.onload = () => { - if (typeof jest !== "undefined") { + if ("nostoReactTest" in window) { window.nosto?.reload({ site: "localhost", })