Skip to content

Commit

Permalink
Merge pull request #97 from Nosto/direct-jsdom-usage
Browse files Browse the repository at this point in the history
Use JSDOM directly
  • Loading branch information
timowestnosto authored Aug 14, 2024
2 parents 9b42aa4 + 2d3f1ac commit e5891f7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
14 changes: 14 additions & 0 deletions spec/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { JSDOM } = require("jsdom")

const { window } = new JSDOM("<html></html>", {
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
4 changes: 2 additions & 2 deletions src/components/NostoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand Down Expand Up @@ -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",
})
Expand Down

0 comments on commit e5891f7

Please sign in to comment.