Skip to content

Commit

Permalink
[Tests] switch to tape
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 26, 2023
1 parent d0b9c94 commit 9a0ab35
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 47 deletions.
3 changes: 0 additions & 3 deletions .eslintrc
Expand Up @@ -13,9 +13,6 @@
},
{
"files": "test/**/*.js",
"env": {
"mocha": true
},
"rules": {
"id-length": "off",
"getter-return": "off",
Expand Down
9 changes: 9 additions & 0 deletions .nycrc
@@ -0,0 +1,9 @@
{
"all": true,
"check-coverage": false,
"reporter": ["text-summary", "text", "html", "json"],
"exclude": [
"coverage",
"test"
]
}
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -19,15 +19,19 @@
"scripts": {
"lint": "eslint --ext=js,mjs .",
"pretest": "npm run lint",
"test": "mocha"
"tests-only": "nyc tape 'test/**/*.js'",
"test": "npm run tests-only",
"posttest": "aud --production"
},
"dependencies": {
"kind-of": "^3.0.2"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.1.0",
"aud": "^2.0.3",
"eslint": "=8.8.0",
"mocha": "*"
"nyc": "^10.3.2",
"tape": "^5.7.2"
},
"keywords": [
"accessor",
Expand Down
95 changes: 53 additions & 42 deletions test/index.js
@@ -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();
});

0 comments on commit 9a0ab35

Please sign in to comment.