Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 10, 2019
1 parent 2a8284c commit dec24eb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
@@ -1,5 +1,15 @@
{
"root": true,

"extends": "@ljharb"
"extends": "@ljharb",

"overrides": [
{
"files": "test/**",
"globals": {
"WeakMap": false,
"WeakSet": false,
},
},
],
}
11 changes: 9 additions & 2 deletions package.json
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"pretest": "npm run lint",
"lint": "eslint .",
"test": "echo \"Error: no test specified\" && exit 1"
"tests-only": "node test",
"posttests-only": "node -e \"require('es5-shim'); require('es6-shim'); require('./test');\"",
"test": "npm run tests-only"
},
"repository": {
"type": "git",
Expand All @@ -27,6 +29,11 @@
"homepage": "https://github.com/inspect-js/is-set#readme",
"devDependencies": {
"@ljharb/eslint-config": "^15.0.1",
"eslint": "^6.6.0"
"es5-shim": "^4.5.13",
"es6-shim": "^0.35.5",
"eslint": "^6.6.0",
"for-each": "^0.3.3",
"object-inspect": "^1.7.0",
"tape": "^4.11.0"
}
}
59 changes: 59 additions & 0 deletions test/index.js
@@ -0,0 +1,59 @@
'use strict';

var test = require('tape');
var debug = require('object-inspect');
var forEach = require('for-each');

var isSet = require('..');

test('non-collections', function (t) {
forEach([
null,
undefined,
true,
false,
42,
0,
-0,
NaN,
Infinity,
'',
'foo',
/a/g,
[],
{},
function () {}
], function (nonCollection) {
t.equal(isSet(nonCollection), false, debug(nonCollection) + ' is not a Set');
});

t.end();
});

test('Maps', { skip: typeof Map !== 'function' }, function (t) {
var m = new Map();
t.equal(isSet(m), false, debug(m) + ' is not a Set');

t.end();
});

test('Sets', { skip: typeof Set !== 'function' }, function (t) {
var s = new Set();
t.equal(isSet(s), true, debug(s) + ' is a Set');

t.end();
});

test('WeakMaps', { skip: typeof WeakMap !== 'function' }, function (t) {
var wm = new WeakMap();
t.equal(isSet(wm), false, debug(wm) + ' is not a Set');

t.end();
});

test('WeakSets', { skip: typeof WeakSet !== 'function' }, function (t) {
var ws = new WeakSet();
t.equal(isSet(ws), false, debug(ws) + ' is not a Set');

t.end();
});

0 comments on commit dec24eb

Please sign in to comment.