Skip to content

Commit 481ade1

Browse files
authored
test: fetch with None in json payload (microsoft#1830)
test: fetch with none json payload
1 parent f791b88 commit 481ade1

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

tests/async/test_fetch_global.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,14 @@ async def test_should_throw_an_error_when_max_redirects_is_less_than_0(
325325
server.PREFIX + "/a/redirect1", method=method, max_redirects=-1
326326
)
327327
assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info)
328+
329+
330+
async def test_should_serialize_null_values_in_json(
331+
playwright: Playwright, server: Server
332+
) -> None:
333+
request = await playwright.request.new_context()
334+
server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish()))
335+
response = await request.post(server.PREFIX + "/echo", data={"foo": None})
336+
assert response.status == 200
337+
assert await response.text() == '{"foo":null}'
338+
await request.dispose()

tests/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ def reset(self) -> None:
196196
self.gzip_routes.clear()
197197
self.routes.clear()
198198

199-
def set_route(self, path: str, callback: Callable[[http.Request], Any]) -> None:
199+
def set_route(
200+
self, path: str, callback: Callable[[HttpRequestWithPostBody], Any]
201+
) -> None:
200202
self.routes[path] = callback
201203

202204
def enable_gzip(self, path: str) -> None:

tests/sync/test_fetch_global.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,14 @@ def test_should_throw_an_error_when_max_redirects_is_less_than_0(
235235
server.PREFIX + "/a/redirect1", method=method, max_redirects=-1
236236
)
237237
assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info)
238+
239+
240+
def test_should_serialize_null_values_in_json(
241+
playwright: Playwright, server: Server
242+
) -> None:
243+
request = playwright.request.new_context()
244+
server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish()))
245+
response = request.post(server.PREFIX + "/echo", data={"foo": None})
246+
assert response.status == 200
247+
assert response.text() == '{"foo":null}'
248+
request.dispose()

0 commit comments

Comments
 (0)