@@ -69,24 +69,48 @@ describe("fetchJsonByLocale", () => {
69
69
let url : string
70
70
let requestInit : RequestInit
71
71
72
- before ( ( ) => {
73
- global . fetch = function ( u : string , i : RequestInit ) : Promise < Response > {
74
- url = u
75
- requestInit = i
76
-
77
- return Promise . resolve ( new ResponseMock ( 200 , `{"foo": "bar"}` ) )
78
- }
79
-
80
- source = fetchJsonByLocale ( "/test/path" , {
81
- method : "POST" ,
72
+ describe ( "found" , ( ) => {
73
+ before ( ( ) => {
74
+ global . fetch = function ( u : string , i : RequestInit ) : Promise < Response > {
75
+ url = u
76
+ requestInit = i
77
+
78
+ return Promise . resolve ( new ResponseMock ( 200 , `{"foo": "bar"}` ) )
79
+ }
80
+
81
+ source = fetchJsonByLocale ( "/test/path" , {
82
+ method : "POST" ,
83
+ } )
84
+ } )
85
+
86
+ it ( "should load de.json" , async ( ) => {
87
+ const json = await source ( new Locale ( "de" ) )
88
+ expect ( json ) . toBe ( `{"foo": "bar"}` )
89
+ expect ( url ) . toBe ( "/test/path/de.json" )
90
+ expect ( requestInit . method ) . toBe ( "POST" )
82
91
} )
83
92
} )
84
93
85
- it ( "should load de.json" , async ( ) => {
86
- const json = await source ( new Locale ( "de" ) )
87
- expect ( json ) . toBe ( `{"foo": "bar"}` )
88
- expect ( url ) . toBe ( "/test/path/de.json" )
89
- expect ( requestInit . method ) . toBe ( "POST" )
94
+ describe ( "not found" , ( ) => {
95
+ before ( ( ) => {
96
+ global . fetch = function ( u : string , i : RequestInit ) : Promise < Response > {
97
+ url = u
98
+ requestInit = i
99
+
100
+ return Promise . resolve ( new ResponseMock ( 404 , "" ) )
101
+ }
102
+
103
+ source = fetchJsonByLocale ( "/test/path" , {
104
+ method : "POST" ,
105
+ } )
106
+ } )
107
+
108
+ it ( "should load de.json" , async ( ) => {
109
+ const json = await source ( new Locale ( "de" ) )
110
+ expect ( json ) . toBeUndefined ( )
111
+ expect ( url ) . toBe ( "/test/path/de.json" )
112
+ expect ( requestInit . method ) . toBe ( "POST" )
113
+ } )
90
114
} )
91
115
} )
92
116
0 commit comments