diff options
| author | 8cy <[email protected]> | 2020-04-03 02:37:42 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-04-03 02:37:42 -0700 |
| commit | 60867fb030bae582082340ead7dbc7efdc2f5398 (patch) | |
| tree | 4c6a7356351be2e4914e15c4703172597c45656e /node_modules/needle/test/querystring_spec.js | |
| parent | commenting (diff) | |
| download | s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.tar.xz s5nical-60867fb030bae582082340ead7dbc7efdc2f5398.zip | |
2020/04/03, 02:34, v1.2.0
Diffstat (limited to 'node_modules/needle/test/querystring_spec.js')
| -rw-r--r-- | node_modules/needle/test/querystring_spec.js | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/node_modules/needle/test/querystring_spec.js b/node_modules/needle/test/querystring_spec.js new file mode 100644 index 0000000..34c1748 --- /dev/null +++ b/node_modules/needle/test/querystring_spec.js @@ -0,0 +1,128 @@ +var should = require('should'), + stringify = require('../lib/querystring').build; + +describe('stringify', function() { + + describe('with null', function() { + + it('throws', function() { + (function() { + var res = stringify(null); + }).should.throw(); + }) + + }) + + describe('with a number', function() { + + it('throws', function() { + (function() { + var res = stringify(100); + }).should.throw(); + }) + + }) + + describe('with a string', function() { + + describe('that is empty', function() { + + it('throws', function() { + (function() { + var res = stringify(''); + }).should.throw(); + }) + + }) + + describe('that doesnt contain an equal sign', function() { + + it('throws', function() { + (function() { + var res = stringify('boomshagalaga'); + }).should.throw(); + }) + + }) + + describe('that contains an equal sign', function() { + + it('works', function() { + var res = stringify('hello=123'); + res.should.eql('hello=123'); + }) + + }) + + }) + + describe('with an array', function() { + + describe('with key val objects', function() { + + it('works', function() { + var res = stringify([ {foo: 'bar'} ]); + res.should.eql('foo=bar'); + }) + + }) + + describe('where all elements are strings with an equal sign', function() { + + it('works', function() { + var res = stringify([ 'bar=123', 'quux=' ]); + res.should.eql('bar=123&quux='); + }) + + }) + + describe('with random words', function() { + + it('throws', function() { + (function() { + var res = stringify(['hello', 'there']); + }).should.throw(); + }) + + }) + + describe('with integers', function() { + + it('throws', function() { + (function() { + var res = stringify([123, 432]); + }).should.throw(); + }) + + }) + + }) + + describe('with an object', function() { + + it('works', function() { + var res = stringify({ test: 100 }); + res.should.eql('test=100'); + }) + + describe('with object where val is an array', function() { + + it('works', function() { + var res = stringify({ foo: ['bar', 'baz'] }); + res.should.eql('foo[]=bar&foo[]=baz'); + }) + + }) + + describe('with object where val is an array of key val objects', function() { + + it('works', function() { + var res = stringify({ foo: [{'1': 'bar'}, {'2': 'baz'}] }); + res.should.eql('foo[][1]=bar&foo[][2]=baz'); + }) + + }) + + }) + +}) |