Skip to content

Commit

Permalink
update to lab 5, fix tests, cleanup lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Oct 23, 2014
1 parent a1c7cca commit 5ba488f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
8 changes: 4 additions & 4 deletions Makefile
@@ -1,8 +1,8 @@
test:
@node node_modules/lab/bin/lab
@node node_modules/lab/bin/lab -L
test-cov:
@node node_modules/lab/bin/lab -t 100
@node node_modules/lab/bin/lab -t 100 -L
test-cov-html:
@node node_modules/lab/bin/lab -r html -o coverage.html
@node node_modules/lab/bin/lab -L -r html -o coverage.html

.PHONY: test test-cov test-cov-html
.PHONY: test test-cov test-cov-html
4 changes: 2 additions & 2 deletions lib/utils.js
Expand Up @@ -88,7 +88,7 @@ exports.compact = function (obj, refs) {
if (Array.isArray(obj)) {
var compacted = [];

for (var i = 0, l = obj.length; i < l; ++i) {
for (var i = 0, il = obj.length; i < il; ++i) {
if (typeof obj[i] !== 'undefined') {
compacted.push(obj[i]);
}
Expand All @@ -98,7 +98,7 @@ exports.compact = function (obj, refs) {
}

var keys = Object.keys(obj);
for (var i = 0, il = keys.length; i < il; ++i) {
for (i = 0, il = keys.length; i < il; ++i) {
var key = keys[i];
obj[key] = exports.compact(obj[key], refs);
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -6,7 +6,8 @@
"main": "index.js",
"dependencies": {},
"devDependencies": {
"lab": "4.x.x"
"code": "^1.2.0",
"lab": "5.x.x"
},
"scripts": {
"test": "make test-cov"
Expand Down
39 changes: 22 additions & 17 deletions test/parse.js
@@ -1,5 +1,7 @@
/* eslint no-extend-native:0 */
// Load modules

var Code = require('code');
var Lab = require('lab');
var Qs = require('../');

Expand All @@ -12,7 +14,7 @@ var internals = {};
// Test shortcuts

var lab = exports.lab = Lab.script();
var expect = Lab.expect;
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;

Expand Down Expand Up @@ -303,14 +305,14 @@ describe('parse()', function () {
it('parses an object', function (done) {

var input = {
"user[name]": {"pop[bob]": 3},
"user[email]": null
'user[name]': {'pop[bob]': 3},
'user[email]': null
};

var expected = {
"user": {
"name": {"pop[bob]": 3},
"email": null
'user': {
'name': {'pop[bob]': 3},
'email': null
}
};

Expand All @@ -323,14 +325,14 @@ describe('parse()', function () {
it('parses an object and not child values', function (done) {

var input = {
"user[name]": {"pop[bob]": { "test": 3 }},
"user[email]": null
'user[name]': {'pop[bob]': { 'test': 3 }},
'user[email]': null
};

var expected = {
"user": {
"name": {"pop[bob]": { "test": 3 }},
"email": null
'user': {
'name': {'pop[bob]': { 'test': 3 }},
'email': null
}
};

Expand All @@ -344,8 +346,9 @@ describe('parse()', function () {

var tempBuffer = global.Buffer;
delete global.Buffer;
expect(Qs.parse('a=b&c=d')).to.deep.equal({ a: 'b', c: 'd' });
var result = Qs.parse('a=b&c=d');
global.Buffer = tempBuffer;
expect(result).to.deep.equal({ a: 'b', c: 'd' });
done();
});

Expand All @@ -365,10 +368,10 @@ describe('parse()', function () {
expect(function () {

parsed = Qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });
}).to.not.throw(Error);
}).to.not.throw();

expect(parsed).to.have.key('foo');
expect(parsed.foo).to.have.keys('bar', 'baz');
expect(parsed).to.contain('foo');
expect(parsed.foo).to.contain('bar', 'baz');
expect(parsed.foo.bar).to.equal('baz');
expect(parsed.foo.baz).to.deep.equal(a);
done();
Expand All @@ -378,9 +381,11 @@ describe('parse()', function () {

var a = Object.create(null);
a.b = 'c';

expect(Qs.parse(a)).to.deep.equal({ b: 'c' });
expect(Qs.parse({ a: a })).to.deep.equal({ a: { b: 'c' } });
var result = Qs.parse({ a: a });
expect(result).to.contain('a');
expect(result.a).to.deep.equal(a);
done();
});

Expand Down
4 changes: 3 additions & 1 deletion test/stringify.js
@@ -1,5 +1,7 @@
/* eslint no-extend-native:0 */
// Load modules

var Code = require('code');
var Lab = require('lab');
var Qs = require('../');

Expand All @@ -12,7 +14,7 @@ var internals = {};
// Test shortcuts

var lab = exports.lab = Lab.script();
var expect = Lab.expect;
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;

Expand Down

0 comments on commit 5ba488f

Please sign in to comment.