Skip to content

Commit

Permalink
Moved is.thenable from Array checks to Object checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ironmaniiith committed Mar 27, 2018
1 parent 43bd1b8 commit 360b886
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
9 changes: 5 additions & 4 deletions is.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,11 @@
// propertyDefined method does not support 'all' and 'any' interfaces
is.propertyDefined.api = ['not'];

// is a given value thenable (like Promise)?
is.thenable = function(value) {
return is.object(value) && typeof value.then === 'function';
};

// Array checks
/* -------------------------------------------------------------------------- */

Expand Down Expand Up @@ -856,10 +861,6 @@
return true;
};

// is a given value thenable (like Promise)?
is.thenable = function(value) {
return is.object(value) && typeof value.then === 'function';
};

// API
// Set 'not', 'all' and 'any' interfaces to methods based on their api property
Expand Down
24 changes: 12 additions & 12 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,18 @@
});
});
checkApi('domNode');

describe('is.thenable', function() {
it('should return true if passed parameter type is Promise', function() {
var promise = Promise.resolve(true); // eslint-disable-line no-undef
expect(is.thenable(promise)).to.be.true;
});
it('should return false if passed parameter type is not Promise', function() {
var notPromise = 'test';
expect(is.thenable(notPromise)).to.be.false;
});
});
checkApi('thenable');
});

describe('array checks', function() {
Expand Down Expand Up @@ -1177,16 +1189,4 @@
checkApi('inArray', ['not']);
});

describe('is.thenable', function() {
it('should return true if passed parameter type is Promise', function() {
var promise = Promise.resolve(true); // eslint-disable-line no-undef
expect(is.thenable(promise)).to.be.true;
});
it('should return false if passed parameter type is not Promise', function() {
var notPromise = 'test';
expect(is.thenable(notPromise)).to.be.false;
});
});
checkApi('thenable');

}(this));

0 comments on commit 360b886

Please sign in to comment.