diff --git a/tests/async/test_fetch_global.py b/tests/async/test_fetch_global.py index 6a915fc49..2b6242e2a 100644 --- a/tests/async/test_fetch_global.py +++ b/tests/async/test_fetch_global.py @@ -325,3 +325,14 @@ async def test_should_throw_an_error_when_max_redirects_is_less_than_0( server.PREFIX + "/a/redirect1", method=method, max_redirects=-1 ) assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info) + + +async def test_should_serialize_null_values_in_json( + playwright: Playwright, server: Server +) -> None: + request = await playwright.request.new_context() + server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish())) + response = await request.post(server.PREFIX + "/echo", data={"foo": None}) + assert response.status == 200 + assert await response.text() == '{"foo":null}' + await request.dispose() diff --git a/tests/server.py b/tests/server.py index 9b486af3c..2bd3e672a 100644 --- a/tests/server.py +++ b/tests/server.py @@ -196,7 +196,9 @@ def reset(self) -> None: self.gzip_routes.clear() self.routes.clear() - def set_route(self, path: str, callback: Callable[[http.Request], Any]) -> None: + def set_route( + self, path: str, callback: Callable[[HttpRequestWithPostBody], Any] + ) -> None: self.routes[path] = callback def enable_gzip(self, path: str) -> None: diff --git a/tests/sync/test_fetch_global.py b/tests/sync/test_fetch_global.py index fc30cc00c..a45c207da 100644 --- a/tests/sync/test_fetch_global.py +++ b/tests/sync/test_fetch_global.py @@ -235,3 +235,14 @@ def test_should_throw_an_error_when_max_redirects_is_less_than_0( server.PREFIX + "/a/redirect1", method=method, max_redirects=-1 ) assert "'max_redirects' must be greater than or equal to '0'" in str(exc_info) + + +def test_should_serialize_null_values_in_json( + playwright: Playwright, server: Server +) -> None: + request = playwright.request.new_context() + server.set_route("/echo", lambda req: (req.write(req.post_body), req.finish())) + response = request.post(server.PREFIX + "/echo", data={"foo": None}) + assert response.status == 200 + assert response.text() == '{"foo":null}' + request.dispose()