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 6af0730 commit 2e8f26d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
12 changes: 11 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 @@ -29,6 +31,11 @@
"homepage": "https://github.com/inspect-js/is-weakset#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
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict';

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

var isWeakSet = require('..');

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

t.end();
});

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

t.end();
});

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

t.end();
});

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

t.end();
});

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

t.end();
});

0 comments on commit 2e8f26d

Please sign in to comment.