-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
382784c
commit ab67be9
Showing
24 changed files
with
1,816 additions
and
1,844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,70 @@ | ||
import "@testing-library/jest-dom" | ||
import { | ||
fromLiquidTemplate, | ||
fromRemoteLiquidTemplate, | ||
defaultLiquidTemplate as liquidTemplate, | ||
fromLiquidTemplate, | ||
fromRemoteLiquidTemplate, | ||
defaultLiquidTemplate as liquidTemplate, | ||
} from "../src/liquid" | ||
import { | ||
handleAutocomplete, | ||
hooks, | ||
autocompleteSuite, | ||
handleAutocomplete, | ||
hooks, | ||
autocompleteSuite, | ||
} from "./suites/autocomplete" | ||
import { waitFor } from "@testing-library/dom" | ||
|
||
function libraryScript() { | ||
const liquidScript = document.createElement("script") | ||
liquidScript.src = | ||
"https://cdn.jsdelivr.net/npm/[email protected]/dist/liquid.browser.min.js" | ||
document.body.appendChild(liquidScript) | ||
const liquidScript = document.createElement("script") | ||
liquidScript.src = | ||
"https://cdn.jsdelivr.net/npm/[email protected]/dist/liquid.browser.min.js" | ||
document.body.appendChild(liquidScript) | ||
} | ||
|
||
describe("fromLiquidTemplate", () => { | ||
autocompleteSuite({ | ||
render: () => fromLiquidTemplate(liquidTemplate), | ||
libraryScript, | ||
}) | ||
autocompleteSuite({ | ||
render: () => fromLiquidTemplate(liquidTemplate), | ||
libraryScript, | ||
}) | ||
}) | ||
|
||
describe("fromRemoteLiquidTemplate", () => { | ||
hooks(libraryScript) | ||
hooks(libraryScript) | ||
|
||
it("fetches remote templates url", async () => { | ||
const openSpy = jest.spyOn(XMLHttpRequest.prototype, "open") | ||
const sendSpy = jest.spyOn(XMLHttpRequest.prototype, "send") | ||
it("fetches remote templates url", async () => { | ||
const openSpy = jest.spyOn(XMLHttpRequest.prototype, "open") | ||
const sendSpy = jest.spyOn(XMLHttpRequest.prototype, "send") | ||
|
||
const mockUrl = "template.liquid" | ||
const render = fromRemoteLiquidTemplate(mockUrl) | ||
const mockUrl = "template.liquid" | ||
const render = fromRemoteLiquidTemplate(mockUrl) | ||
|
||
const mockXhr = { | ||
open: jest.fn(), | ||
send: jest.fn(), | ||
status: 200, | ||
responseText: liquidTemplate, | ||
onload: jest.fn(), | ||
onerror: jest.fn(), | ||
} | ||
const mockXhr = { | ||
open: jest.fn(), | ||
send: jest.fn(), | ||
status: 200, | ||
responseText: liquidTemplate, | ||
onload: jest.fn(), | ||
onerror: jest.fn(), | ||
} | ||
|
||
openSpy.mockImplementation((method, url) => { | ||
if (url === mockUrl) { | ||
return mockXhr.open(method, url) | ||
} | ||
return openSpy.mock.calls[0] | ||
}) | ||
openSpy.mockImplementation((method, url) => { | ||
if (url === mockUrl) { | ||
return mockXhr.open(method, url) | ||
} | ||
return openSpy.mock.calls[0] | ||
}) | ||
|
||
sendSpy.mockImplementation(() => { | ||
return sendSpy.mock.calls[0] | ||
}) | ||
sendSpy.mockImplementation(() => { | ||
return sendSpy.mock.calls[0] | ||
}) | ||
|
||
await waitFor(() => handleAutocomplete(render)) | ||
await waitFor(() => handleAutocomplete(render)) | ||
|
||
await waitFor( | ||
() => { | ||
expect(openSpy).toHaveBeenCalledWith("GET", mockUrl) | ||
expect(sendSpy).toHaveBeenCalled() | ||
}, | ||
{ | ||
timeout: 1000, | ||
} | ||
) | ||
}) | ||
await waitFor( | ||
() => { | ||
expect(openSpy).toHaveBeenCalledWith("GET", mockUrl) | ||
expect(sendSpy).toHaveBeenCalled() | ||
}, | ||
{ | ||
timeout: 1000, | ||
} | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
import "@testing-library/jest-dom" | ||
import { | ||
fromMustacheTemplate, | ||
fromRemoteMustacheTemplate, | ||
defaultMustacheTemplate as mustacheTemplate, | ||
fromMustacheTemplate, | ||
fromRemoteMustacheTemplate, | ||
defaultMustacheTemplate as mustacheTemplate, | ||
} from "../src/mustache" | ||
import { | ||
autocompleteSuite, | ||
handleAutocomplete, | ||
hooks, | ||
autocompleteSuite, | ||
handleAutocomplete, | ||
hooks, | ||
} from "./suites/autocomplete" | ||
import { waitFor } from "@testing-library/dom" | ||
|
||
function libraryScript() { | ||
const mustacheScript = document.createElement("script") | ||
mustacheScript.src = "https://unpkg.com/[email protected]/mustache.min.js" | ||
document.body.appendChild(mustacheScript) | ||
const mustacheScript = document.createElement("script") | ||
mustacheScript.src = "https://unpkg.com/[email protected]/mustache.min.js" | ||
document.body.appendChild(mustacheScript) | ||
} | ||
|
||
describe("fromMustacheTemplate", () => { | ||
autocompleteSuite({ | ||
render: () => fromMustacheTemplate(mustacheTemplate), | ||
libraryScript, | ||
}) | ||
autocompleteSuite({ | ||
render: () => fromMustacheTemplate(mustacheTemplate), | ||
libraryScript, | ||
}) | ||
}) | ||
|
||
describe("fromRemoteMustacheTemplate", () => { | ||
hooks(libraryScript) | ||
hooks(libraryScript) | ||
|
||
it("fetches remote templates url", async () => { | ||
const openSpy = jest.spyOn(XMLHttpRequest.prototype, "open") | ||
const sendSpy = jest.spyOn(XMLHttpRequest.prototype, "send") | ||
it("fetches remote templates url", async () => { | ||
const openSpy = jest.spyOn(XMLHttpRequest.prototype, "open") | ||
const sendSpy = jest.spyOn(XMLHttpRequest.prototype, "send") | ||
|
||
const mockUrl = "template.mustache" | ||
const render = fromRemoteMustacheTemplate(mockUrl) | ||
const mockUrl = "template.mustache" | ||
const render = fromRemoteMustacheTemplate(mockUrl) | ||
|
||
const mockXhr = { | ||
open: jest.fn(), | ||
send: jest.fn(), | ||
status: 200, | ||
responseText: mustacheTemplate, | ||
onload: jest.fn(), | ||
onerror: jest.fn(), | ||
} | ||
const mockXhr = { | ||
open: jest.fn(), | ||
send: jest.fn(), | ||
status: 200, | ||
responseText: mustacheTemplate, | ||
onload: jest.fn(), | ||
onerror: jest.fn(), | ||
} | ||
|
||
openSpy.mockImplementation((method, url) => { | ||
if (url === mockUrl) { | ||
return mockXhr.open(method, url) | ||
} | ||
return openSpy.mock.calls[0] | ||
}) | ||
openSpy.mockImplementation((method, url) => { | ||
if (url === mockUrl) { | ||
return mockXhr.open(method, url) | ||
} | ||
return openSpy.mock.calls[0] | ||
}) | ||
|
||
sendSpy.mockImplementation(() => { | ||
return sendSpy.mock.calls[0] | ||
}) | ||
sendSpy.mockImplementation(() => { | ||
return sendSpy.mock.calls[0] | ||
}) | ||
|
||
await waitFor(() => handleAutocomplete(render)) | ||
await waitFor(() => handleAutocomplete(render)) | ||
|
||
await waitFor( | ||
() => { | ||
expect(openSpy).toHaveBeenCalledWith("GET", mockUrl) | ||
expect(sendSpy).toHaveBeenCalled() | ||
}, | ||
{ | ||
timeout: 1000, | ||
} | ||
) | ||
}) | ||
await waitFor( | ||
() => { | ||
expect(openSpy).toHaveBeenCalledWith("GET", mockUrl) | ||
expect(sendSpy).toHaveBeenCalled() | ||
}, | ||
{ | ||
timeout: 1000, | ||
} | ||
) | ||
}) | ||
}) |
Oops, something went wrong.