UNPKG

app-decorators

Version:

Collection of useful ES7 Decorators, writtin in ES6, that can be used for building webapps

186 lines (151 loc) 8.49 kB
System.register(['app-decorators/src/libs/element-to-function', '../../src/helpers/queryString'], function (_export, _context) { "use strict"; var _elementToFunc, queryString; return { setters: [function (_appDecoratorsSrcLibsElementToFunction) { _elementToFunc = _appDecoratorsSrcLibsElementToFunction.default; }, function (_srcHelpersQueryString) { queryString = _srcHelpersQueryString.queryString; }], execute: function () { describe('queryString', function () { describe('parse method', function () { it('query strings starting with a `?`', function () { should(queryString.parse('?foo=bar')).be.containEql({ foo: 'bar' }); }); it('query strings starting with a `&`', function () { should(queryString.parse('#foo=bar')).be.containEql({ foo: 'bar' }); }); it('query strings starting with a `&`', function () { should(queryString.parse('&foo=bar&foo=baz')).be.containEql({ foo: ['bar', 'baz'] }); }); it('parse a query string', function () { should(queryString.parse('foo=bar')).be.containEql({ foo: 'bar' }); }); it('parse multiple query string', function () { should(queryString.parse('foo=bar&key=val')).be.containEql({ foo: 'bar', key: 'val' }); }); it('parse query string without a value', function () { should(queryString.parse('foo')).be.containEql({ foo: null }); should(queryString.parse('foo&key')).be.containEql({ foo: null, key: null }); should(queryString.parse('foo=bar&key')).be.containEql({ foo: 'bar', key: null }); should(queryString.parse('a&a=')).be.containEql({ a: [null, null] }); }); it('return empty object if no qss can be found', function () { should(queryString.parse('?')).be.containEql({}); should(queryString.parse('&')).be.containEql({}); should(queryString.parse('#')).be.containEql({}); should(queryString.parse('')).be.containEql({}); should(queryString.parse(' ')).be.containEql({}); }); it('handle `+` correctly', function () { should(queryString.parse('foo+faz=bar+baz++')).be.containEql({ 'foo faz': 'bar baz ' }); }); it('handle multiple of the same key', function () { should(queryString.parse('foo=bar&foo=baz')).be.containEql({ foo: ['bar', 'baz'] }); }); it('handle multiple of the same key', function () { should(queryString.parse('foo=bar&foo=baz')).be.containEql({ foo: ['bar', 'baz'] }); }); it('query strings params including embedded `=`', function () { should(queryString.parse('?param=http%3A%2F%2Fsomeurl%3Fid%3D2837')).be.containEql({ param: 'http://someurl?id=2837' }); }); it('query strings params including raw `=`', function () { should(queryString.parse('?param=http://someurl?id=2837')).be.containEql({ param: 'http://someurl?id=2837' }); }); it('object properties', function () { should(queryString.parse('hasOwnProperty=foo')).be.containEql({ hasOwnProperty: 'foo' }); }); }); describe('stringify method', function () { it('stringify', function () { queryString.stringify({ foo: 'bar' }).should.be.equal('foo=bar'); queryString.stringify({ foo: 'bar', 'bar': 'baz' }).should.be.equal('foo=bar&bar=baz'); }); it('different types', function () { queryString.stringify('').should.be.equal(''); queryString.stringify(0).should.be.equal(''); queryString.stringify(1).should.be.equal(''); queryString.stringify([]).should.be.equal(''); queryString.stringify(true).should.be.equal(''); }); it('URI encode', function () { queryString.stringify({ 'foo bar': 'baz faz' }).should.be.equal('foo%20bar=baz%20faz'); // FIXME: should be implemented when its required //queryString.stringify({'foo bar': "baz\'faz"}).should.be.equal('foo%20bar=baz%27faz'); }); it('no encoding', function () { queryString.stringify({ 'foo:bar': 'baz:faz' }, false).should.be.equal('foo:bar=baz:faz'); }); it('handle array value', function () { queryString.stringify({ abc: 'abc', foo: ['bar', 'baz'] }).should.be.equal('abc=abc&foo=bar&foo=baz'); }); it('handle empty array value', function () { queryString.stringify({ abc: 'abc', foo: [] }).should.be.equal('abc=abc'); }); it('should not encode undefined values', function () { queryString.stringify({ abc: undefined, foo: 'baz' }).should.be.equal('foo=baz'); }); it('should encode null values as just a key', function () { queryString.stringify({ 'x y z': null, 'abc': null, 'foo': 'baz' }).should.be.equal('x%20y%20z&abc&foo=baz'); }); it('handle null values in array', function () { queryString.stringify({ foo: null, bar: [null, 'baz'] }).should.be.equal('foo&bar&bar=baz'); }); it('handle undefined values in array', function () { queryString.stringify({ foo: null, bar: [undefined, 'baz'] }).should.be.equal('foo&bar=baz'); }); it('handle undefined and null values in array', function () { queryString.stringify({ foo: null, bar: [undefined, null, 'baz'] }).should.be.equal('foo&bar&bar=baz'); }); // FIXME: should be implemented when its required it.skip('strict encoding', function () { queryString.stringify({ foo: '\'bar\'' }).should.be.equal('foo=%27bar%27'); queryString.stringify({ foo: ['\'bar\'', '!baz'] }).should.be.equal('foo=%27bar%27&foo=!baz'); }); // FIXME: should be implemented when its required it.skip('loose encoding', function () { queryString.stringify({ foo: '\'bar\'' }).should.be.equal('foo=\'bar\''); queryString.stringify({ foo: ['\'bar\'', '!baz'] }).should.be.equal('foo=\'bar\''); }); }); }); } }; }); //# sourceMappingURL=querString.spec.js.map