Skip to content

Commit

Permalink
ServerSideRender: tests for http-build-query
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdan Dimofte committed Jun 18, 2018
1 parent 0ebc884 commit 6a4d3d2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions components/server-side-render/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import httpBuildQuery from 'http-build-query';

// The following tests are adapted to the behavior of http-build-query v0.7.0,
// to help mitigating possible regressions in the upstream library.
describe( 'http-build-query', function() {
test( 'should return an empty string for empty input', function() {
expect( httpBuildQuery( null ) ).toBe( '' );
expect( httpBuildQuery() ).toBe( '' );
expect( httpBuildQuery( {} ) ).toBe( '' );
} );

test( 'should format basic url params ', function() {
expect(
httpBuildQuery( {
stringArg: 'test',
nullArg: null,
emptyArg: '',
numberArg: 123,
} )
).toBe(
encodeURI(
'stringArg=test&nullArg=&emptyArg=&numberArg=123'
)
);
} );

test( 'should format object params ', function() {
expect(
httpBuildQuery( {
objectArg: {
stringProp: 'test',
numberProp: 123,
},
} )
).toBe(
encodeURI(
'objectArg[stringProp]=test&objectArg[numberProp]=123'
)
);
} );

test( 'should format an array of objects', function() {
expect(
httpBuildQuery( {
children: [
{
name: 'bobby',
age: 12,
sex: 'M',
},
{
name: 'sally',
age: 8,
sex: 'F',
},
],
} )
).toBe(
encodeURI(
'children[0][name]=bobby&children[0][age]=12&children[0][sex]=M&children[1][name]=sally&children[1][age]=8&children[1][sex]=F'
)
);
} );
} );

0 comments on commit 6a4d3d2

Please sign in to comment.