@@ -66,7 +66,7 @@ describe("vscode", () => {
66
66
67
67
_document . body . removeChild ( mockElement )
68
68
} )
69
- it ( "should return have loadBundle property if _resolvedLangaugePackCoreLocation" , ( ) => {
69
+ it ( "should return have loadBundle property if _resolvedLangaugePackCoreLocation" , async ( ) => {
70
70
const mockElement = _document . createElement ( "div" )
71
71
const dataSettings = {
72
72
locale : "en" ,
@@ -84,11 +84,19 @@ describe("vscode", () => {
84
84
85
85
// TODO@jsjoeio write the tests here
86
86
// 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 )
88
92
// 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" } )
89
95
// see https://www.npmjs.com/package/jest-fetch-mock#usage
90
96
// 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" } )
92
100
// 4. call it again and calls the callback with the cached json
93
101
94
102
_document . body . removeChild ( mockElement )
0 commit comments