Skip to content

Commit d94947e

Browse files
committed
wip: add first tests
1 parent ac55e0d commit d94947e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

test/unit/browser/pages/vscode.test.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe("vscode", () => {
6666

6767
_document.body.removeChild(mockElement)
6868
})
69-
it("should return have loadBundle property if _resolvedLangaugePackCoreLocation", () => {
69+
it("should return have loadBundle property if _resolvedLangaugePackCoreLocation", async () => {
7070
const mockElement = _document.createElement("div")
7171
const dataSettings = {
7272
locale: "en",
@@ -84,11 +84,19 @@ describe("vscode", () => {
8484

8585
// TODO@jsjoeio write the tests here
8686
// 1. call nlsConfig.loadBundle()
87-
// 2. check that fetch was called
87+
const mockCallbackFn = jest.fn((undefined, bundle) => {
88+
return bundle
89+
})
90+
fetchMock.mockOnce(JSON.stringify({ key: "hello world" }))
91+
await nlsConfig.loadBundle("hello", "en", mockCallbackFn)
8892
// 3. check that the callback was called and has the right json
93+
expect(mockCallbackFn).toHaveBeenCalledTimes(1)
94+
expect(mockCallbackFn).toHaveBeenCalledWith(undefined, { key: "hello world" })
8995
// see https://www.npmjs.com/package/jest-fetch-mock#usage
9096
// see https://www.leighhalliday.com/mock-fetch-jest
91-
fetchMock.mockOnce(JSON.stringify({ key: "hello world" }))
97+
await nlsConfig.loadBundle("hello", "en", mockCallbackFn)
98+
expect(mockCallbackFn).toHaveBeenCalledTimes(2)
99+
expect(mockCallbackFn).toHaveBeenCalledWith(undefined, { key: "hello world" })
92100
// 4. call it again and calls the callback with the cached json
93101

94102
_document.body.removeChild(mockElement)

0 commit comments

Comments
 (0)