Skip to content

Commit c38743c

Browse files
committed
Fix handling a network request body that is not a string
Fix handling a network request body that is not a string
1 parent d0baaeb commit c38743c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

__tests__/xhrNetworkInterceptor.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ describe('Network Interceptor', () => {
6060

6161
it('should set requestBody in network object', (done) => {
6262

63-
const requestBody = { data: [{ item: 'first' }, { item: 'second' }] };
63+
let requestBody = { data: [{ item: 'first' }, { item: 'second' }] };
6464
Interceptor.enableInterception();
6565
Interceptor.setOnDoneCallback((network) => {
66-
expect(network.requestBody).toEqual(requestBody);
66+
expect(network.requestBody).toEqual(JSON.stringify(requestBody));
6767
done();
6868
})
6969
FakeRequest.open(method, url);

utils/XhrNetworkInterceptor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ const XHRInterceptor = {
5656
var cloneNetwork = JSON.parse(JSON.stringify(network));
5757
cloneNetwork.requestBody = data ? data : '';
5858

59+
if (typeof cloneNetwork.requestBody !== "string") {
60+
cloneNetwork.requestBody = JSON.stringify(cloneNetwork.requestBody);
61+
}
62+
5963
if (this.addEventListener) {
6064
this.addEventListener(
6165
'readystatechange',

0 commit comments

Comments
 (0)