1
1
/**
2
2
* @jest -environment jsdom
3
3
*/
4
+ import fetchMock from "jest-fetch-mock"
4
5
import { JSDOM } from "jsdom"
5
6
import {
6
7
getNlsConfiguration ,
@@ -20,6 +21,11 @@ describe("vscode", () => {
20
21
// We use underscores to not confuse with global values
21
22
const { window : _window } = new JSDOM ( )
22
23
_document = _window . document
24
+ fetchMock . enableMocks ( )
25
+ } )
26
+
27
+ afterEach ( ( ) => {
28
+ fetchMock . resetMocks ( )
23
29
} )
24
30
25
31
it ( "should throw an error if no nlsConfigElement" , ( ) => {
@@ -75,18 +81,15 @@ describe("vscode", () => {
75
81
76
82
expect ( nlsConfig . _resolvedLanguagePackCoreLocation ) . not . toBe ( undefined )
77
83
expect ( nlsConfig . loadBundle ) . not . toBe ( undefined )
84
+
78
85
// TODO@jsjoeio write the tests here
79
86
// 1. call nlsConfig.loadBundle()
80
87
// 2. check that fetch was called
81
88
// 3. check that the callback was called and has the right json
89
+ // see https://www.npmjs.com/package/jest-fetch-mock#usage
90
+ // see https://www.leighhalliday.com/mock-fetch-jest
91
+ fetchMock . mockOnce ( JSON . stringify ( { key : "hello world" } ) )
82
92
// 4. call it again and calls the callback with the cached json
83
- /*
84
- A couple unknowns still...
85
-
86
- I need to figure out how to mock the fetch call.
87
-
88
- Once I do that, I can write the tests.
89
- */
90
93
91
94
_document . body . removeChild ( mockElement )
92
95
} )
0 commit comments