Skip to content

Commit

Permalink
Make impl more generic and expand tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
totherik committed Jun 19, 2014
1 parent 2f6258b commit 1654d16
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
4 changes: 3 additions & 1 deletion lib/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,14 @@ exports.create = function create(parent) {

self = this;

if (thing.isObject(data) && !Buffer.isBuffer(data)) {
if (thing.isArray(data) || (thing.isObject(data) && Object.getPrototypeOf(data) === Object.prototype)) {

if (thing.isArray(data)) {

tasks = data.map(function (val) {
return resolve.bind(self, val);
});

} else {
tasks = {};
Object.keys(data).forEach(function (key) {
Expand Down
52 changes: 43 additions & 9 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,51 @@ test('shortstop', function (t) {
});


t.test('preserve buffers', function (t) {
var resolver;
t.test('preserve types', function (t) {

resolver = shortstop.create();
resolver.resolve({ buffer: new Buffer(0) }, function (err, data) {
t.error(err);
t.ok(data);
t.ok(data.buffer);
t.ok(Buffer.isBuffer(data.buffer));
t.end()
t.test('Buffer', function (t) {
var resolver;

resolver = shortstop.create();
resolver.resolve({ buffer: new Buffer(0) }, function (err, data) {
t.error(err);
t.ok(data);
t.ok(data.buffer);
t.ok(Buffer.isBuffer(data.buffer));
t.end()
});
});


t.test('Date', function (t) {
var resolver;

resolver = shortstop.create();
resolver.resolve({ date: new Date() }, function (err, data) {
t.error(err);
t.ok(data);
t.ok(data.date);
t.ok(data.date.constructor === Date);
t.ok(Object.getPrototypeOf(data.date) !== Object.prototype);
t.end()
});
});


t.test('RegExp', function (t) {
var resolver;

resolver = shortstop.create();
resolver.resolve({ regexp: new RegExp('.') }, function (err, data) {
t.error(err);
t.ok(data);
t.ok(data.regexp);
t.ok(data.regexp.constructor === RegExp);
t.ok(Object.getPrototypeOf(data.regexp) !== Object.prototype);
t.end()
});
});

});


Expand Down

0 comments on commit 1654d16

Please sign in to comment.