Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"all": true, | ||
"check-coverage": false, | ||
"reporter": ["text-summary", "text", "html", "json"], | ||
"exclude": [ | ||
"coverage", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
'use strict'; | ||
|
||
require('mocha'); | ||
var assert = require('assert'); | ||
var test = require('tape'); | ||
var isDescriptor = require('../'); | ||
var noop = function () {}; | ||
|
||
describe('isDescriptor', function () { | ||
describe('value type', function () { | ||
it('should be false when not an object:', function () { | ||
assert(!isDescriptor('a')); | ||
assert(!isDescriptor(null)); | ||
assert(!isDescriptor([])); | ||
}); | ||
test('isDescriptor', function (t) { | ||
t.test('should be false when not an object:', function (st) { | ||
st.notOk(isDescriptor('a')); | ||
st.notOk(isDescriptor(null)); | ||
st.notOk(isDescriptor([])); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('should be false when the object has data descriptor properties:', function (st) { | ||
st.notOk(isDescriptor({ get: noop, writable: true })); | ||
st.notOk(isDescriptor({ get: noop, value: true })); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('should not be false when unrecognized properties are defined:', function (st) { | ||
st.ok(isDescriptor({ get: noop, foo: true })); | ||
st.ok(isDescriptor({ get: noop, bar: true })); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('should be false when a get or set are not functions:', function (st) { | ||
st.notOk(isDescriptor({ get: noop, set: 'baz' })); | ||
st.notOk(isDescriptor({ get: 'foo', set: noop })); | ||
st.notOk(isDescriptor({ get: 'foo', bar: 'baz' })); | ||
st.notOk(isDescriptor({ get: 'foo', set: 'baz' })); | ||
st.notOk(isDescriptor({ get: 'foo' })); | ||
|
||
st.end(); | ||
}); | ||
|
||
describe('accessor descriptor:', function () { | ||
it('should be false when the object has data descriptor properties:', function () { | ||
assert(!isDescriptor({ get: noop, writable: true })); | ||
assert(!isDescriptor({ get: noop, value: true })); | ||
}); | ||
|
||
it('should not be false when unrecognized properties are defined:', function () { | ||
assert(isDescriptor({ get: noop, foo: true })); | ||
assert(isDescriptor({ get: noop, bar: true })); | ||
}); | ||
|
||
it('should be false when a get or set are not functions:', function () { | ||
assert(!isDescriptor({ get: noop, set: 'baz' })); | ||
assert(!isDescriptor({ get: 'foo', set: noop })); | ||
assert(!isDescriptor({ get: 'foo', bar: 'baz' })); | ||
assert(!isDescriptor({ get: 'foo', set: 'baz' })); | ||
assert(!isDescriptor({ get: 'foo' })); | ||
}); | ||
|
||
it('should be false when "get" is not defined:', function () { | ||
assert(!isDescriptor({ set: noop })); | ||
}); | ||
|
||
it('should be true when the object has valid properties:', function () { | ||
assert(isDescriptor({ get: noop, set: noop })); | ||
assert(isDescriptor({ get: noop })); | ||
}); | ||
|
||
it('should be false when a value is not the correct type:', function () { | ||
assert(!isDescriptor({ get: noop, set: noop, enumerable: 'foo' })); | ||
assert(!isDescriptor({ set: noop, configurable: 'foo' })); | ||
assert(!isDescriptor({ get: noop, configurable: 'foo' })); | ||
}); | ||
t.test('should be false when "get" is not defined:', function (st) { | ||
st.notOk(isDescriptor({ set: noop })); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('should be true when the object has valid properties:', function (st) { | ||
st.ok(isDescriptor({ get: noop, set: noop })); | ||
st.ok(isDescriptor({ get: noop })); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.test('should be false when a value is not the correct type:', function (st) { | ||
st.notOk(isDescriptor({ get: noop, set: noop, enumerable: 'foo' })); | ||
st.notOk(isDescriptor({ set: noop, configurable: 'foo' })); | ||
st.notOk(isDescriptor({ get: noop, configurable: 'foo' })); | ||
|
||
st.end(); | ||
}); | ||
|
||
t.end(); | ||
}); |