Minor code style tweaks in the tests

This commit is contained in:
Sindre Sorhus 2018-10-30 23:19:19 +07:00
parent c983ffa4cd
commit 9ac56f1be7

View file

@ -8,7 +8,7 @@ import test, {TestContext, Context} from 'ava';
import {JSDOM} from 'jsdom'; import {JSDOM} from 'jsdom';
import {Subject, Observable} from 'rxjs'; import {Subject, Observable} from 'rxjs';
import ZenObservable from 'zen-observable'; import ZenObservable from 'zen-observable';
import m from '..'; import is from '..';
const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8; const isNode8orHigher = Number(process.versions.node.split('.')[0]) >= 8;
const isNode10orHigher = Number(process.versions.node.split('.')[0]) >= 10; const isNode10orHigher = Number(process.versions.node.split('.')[0]) >= 10;
@ -18,7 +18,7 @@ class ErrorSubclassFixture extends Error {}
const {window} = new JSDOM(); const {window} = new JSDOM();
const {document} = window; const {document} = window;
const createDomElement = (el: string) => document.createElement(el); const createDomElement = (element: string) => document.createElement(element);
interface Test { interface Test {
is(value: any): boolean; is(value: any): boolean;
@ -27,19 +27,19 @@ interface Test {
const types = new Map<string, Test>([ const types = new Map<string, Test>([
['undefined', { ['undefined', {
is: m.undefined, is: is.undefined,
fixtures: [ fixtures: [
undefined undefined
] ]
}], }],
['null', { ['null', {
is: m.null_, is: is.null_,
fixtures: [ fixtures: [
null null
] ]
}], }],
['string', { ['string', {
is: m.string, is: is.string,
fixtures: [ fixtures: [
'🦄', '🦄',
'hello world', 'hello world',
@ -47,14 +47,14 @@ const types = new Map<string, Test>([
] ]
}], }],
['emptyString', { ['emptyString', {
is: m.emptyString, is: is.emptyString,
fixtures: [ fixtures: [
'', '',
String() String()
] ]
}], }],
['number', { ['number', {
is: m.number, is: is.number,
fixtures: [ fixtures: [
6, 6,
1.4, 1.4,
@ -65,33 +65,33 @@ const types = new Map<string, Test>([
] ]
}], }],
['boolean', { ['boolean', {
is: m.boolean, is: is.boolean,
fixtures: [ fixtures: [
true, false true, false
] ]
}], }],
['symbol', { ['symbol', {
is: m.symbol, is: is.symbol,
fixtures: [ fixtures: [
Symbol('🦄') Symbol('🦄')
] ]
}], }],
['array', { ['array', {
is: m.array, is: is.array,
fixtures: [ fixtures: [
[1, 2], [1, 2],
new Array(2) // tslint:disable-line:prefer-array-literal new Array(2) // tslint:disable-line:prefer-array-literal
] ]
}], }],
['emptyArray', { ['emptyArray', {
is: m.emptyArray, is: is.emptyArray,
fixtures: [ fixtures: [
[], [],
new Array() new Array()
] ]
}], }],
['function', { ['function', {
is: m.function_, is: is.function_,
fixtures: [ fixtures: [
// tslint:disable:no-unused no-empty no-unused-variable only-arrow-functions no-function-expression // tslint:disable:no-unused no-empty no-unused-variable only-arrow-functions no-function-expression
function foo() {}, function foo() {},
@ -103,53 +103,53 @@ const types = new Map<string, Test>([
] ]
}], }],
['buffer', { ['buffer', {
is: m.buffer, is: is.buffer,
fixtures: [ fixtures: [
Buffer.from('🦄') Buffer.from('🦄')
] ]
}], }],
['object', { ['object', {
is: m.object, is: is.object,
fixtures: [ fixtures: [
{x: 1}, {x: 1},
Object.create({x: 1}) Object.create({x: 1})
] ]
}], }],
['regExp', { ['regExp', {
is: m.regExp, is: is.regExp,
fixtures: [ fixtures: [
/\w/, /\w/,
new RegExp('\\w') new RegExp('\\w')
] ]
}], }],
['date', { ['date', {
is: m.date, is: is.date,
fixtures: [ fixtures: [
new Date() new Date()
] ]
}], }],
['error', { ['error', {
is: m.error, is: is.error,
fixtures: [ fixtures: [
new Error('🦄'), new Error('🦄'),
new ErrorSubclassFixture() new ErrorSubclassFixture()
] ]
}], }],
['nativePromise', { ['nativePromise', {
is: m.nativePromise, is: is.nativePromise,
fixtures: [ fixtures: [
Promise.resolve(), Promise.resolve(),
PromiseSubclassFixture.resolve() PromiseSubclassFixture.resolve()
] ]
}], }],
['promise', { ['promise', {
is: m.promise, is: is.promise,
fixtures: [ fixtures: [
{then() {}, catch() {}} // tslint:disable-line:no-empty {then() {}, catch() {}} // tslint:disable-line:no-empty
] ]
}], }],
['generator', { ['generator', {
is: m.generator, is: is.generator,
fixtures: [ fixtures: [
(function * () { (function * () {
yield 4; yield 4;
@ -157,7 +157,7 @@ const types = new Map<string, Test>([
] ]
}], }],
['generatorFunction', { ['generatorFunction', {
is: m.generatorFunction, is: is.generatorFunction,
fixtures: [ fixtures: [
function * () { function * () {
yield 4; yield 4;
@ -165,137 +165,137 @@ const types = new Map<string, Test>([
] ]
}], }],
['asyncFunction', { ['asyncFunction', {
is: m.asyncFunction, is: is.asyncFunction,
fixtures: [ fixtures: [
async function () {}, // tslint:disable-line:no-empty only-arrow-functions no-function-expression async function () {}, // tslint:disable-line:no-empty only-arrow-functions no-function-expression
async () => {} // tslint:disable-line:no-empty async () => {} // tslint:disable-line:no-empty
] ]
}], }],
['boundFunction', { ['boundFunction', {
is: m.boundFunction, is: is.boundFunction,
fixtures: [ fixtures: [
() => {}, // tslint:disable-line:no-empty () => {}, // tslint:disable-line:no-empty
function () {}.bind(null), // tslint:disable-line:no-empty only-arrow-functions function () {}.bind(null), // tslint:disable-line:no-empty only-arrow-functions
] ]
}], }],
['map', { ['map', {
is: m.map, is: is.map,
fixtures: [ fixtures: [
new Map([['one', '1']]), new Map([['one', '1']]),
] ]
}], }],
['emptyMap', { ['emptyMap', {
is: m.emptyMap, is: is.emptyMap,
fixtures: [ fixtures: [
new Map(), new Map(),
] ]
}], }],
['set', { ['set', {
is: m.set, is: is.set,
fixtures: [ fixtures: [
new Set(['one']) new Set(['one'])
] ]
}], }],
['emptySet', { ['emptySet', {
is: m.emptySet, is: is.emptySet,
fixtures: [ fixtures: [
new Set(), new Set(),
] ]
}], }],
['weakSet', { ['weakSet', {
is: m.weakSet, is: is.weakSet,
fixtures: [ fixtures: [
new WeakSet() new WeakSet()
] ]
}], }],
['weakMap', { ['weakMap', {
is: m.weakMap, is: is.weakMap,
fixtures: [ fixtures: [
new WeakMap() new WeakMap()
] ]
}], }],
['int8Array', { ['int8Array', {
is: m.int8Array, is: is.int8Array,
fixtures: [ fixtures: [
new Int8Array(0) new Int8Array(0)
] ]
}], }],
['uint8Array', { ['uint8Array', {
is: m.uint8Array, is: is.uint8Array,
fixtures: [ fixtures: [
new Uint8Array(0) new Uint8Array(0)
] ]
}], }],
['uint8ClampedArray', { ['uint8ClampedArray', {
is: m.uint8ClampedArray, is: is.uint8ClampedArray,
fixtures: [ fixtures: [
new Uint8ClampedArray(0) new Uint8ClampedArray(0)
] ]
}], }],
['int16Array', { ['int16Array', {
is: m.int16Array, is: is.int16Array,
fixtures: [ fixtures: [
new Int16Array(0) new Int16Array(0)
] ]
}], }],
['uint16Array', { ['uint16Array', {
is: m.uint16Array, is: is.uint16Array,
fixtures: [ fixtures: [
new Uint16Array(0) new Uint16Array(0)
] ]
}], }],
['int32Array', { ['int32Array', {
is: m.int32Array, is: is.int32Array,
fixtures: [ fixtures: [
new Int32Array(0) new Int32Array(0)
] ]
}], }],
['uint32Array', { ['uint32Array', {
is: m.uint32Array, is: is.uint32Array,
fixtures: [ fixtures: [
new Uint32Array(0) new Uint32Array(0)
] ]
}], }],
['float32Array', { ['float32Array', {
is: m.float32Array, is: is.float32Array,
fixtures: [ fixtures: [
new Float32Array(0) new Float32Array(0)
] ]
}], }],
['float64Array', { ['float64Array', {
is: m.float64Array, is: is.float64Array,
fixtures: [ fixtures: [
new Float64Array(0) new Float64Array(0)
] ]
}], }],
['arrayBuffer', { ['arrayBuffer', {
is: m.arrayBuffer, is: is.arrayBuffer,
fixtures: [ fixtures: [
new ArrayBuffer(10) new ArrayBuffer(10)
] ]
}], }],
['dataView', { ['dataView', {
is: m.dataView, is: is.dataView,
fixtures: [ fixtures: [
new DataView(new ArrayBuffer(10)) new DataView(new ArrayBuffer(10))
] ]
}], }],
['nan', { ['nan', {
is: m.nan, is: is.nan,
fixtures: [ fixtures: [
NaN, NaN,
Number.NaN Number.NaN
] ]
}], }],
['nullOrUndefined', { ['nullOrUndefined', {
is: m.nullOrUndefined, is: is.nullOrUndefined,
fixtures: [ fixtures: [
null, null,
undefined undefined
] ]
}], }],
['plainObject', { ['plainObject', {
is: m.plainObject, is: is.plainObject,
fixtures: [ fixtures: [
{x: 1}, {x: 1},
Object.create(null), Object.create(null),
@ -303,20 +303,20 @@ const types = new Map<string, Test>([
] ]
}], }],
['integer', { ['integer', {
is: m.integer, is: is.integer,
fixtures: [ fixtures: [
6 6
] ]
}], }],
['safeInteger', { ['safeInteger', {
is: m.safeInteger, is: is.safeInteger,
fixtures: [ fixtures: [
Math.pow(2, 53) - 1, Math.pow(2, 53) - 1,
-Math.pow(2, 53) + 1 -Math.pow(2, 53) + 1
] ]
}], }],
['domElement', { ['domElement', {
is: m.domElement, is: is.domElement,
fixtures: [ fixtures: [
'div', 'div',
'input', 'input',
@ -327,7 +327,7 @@ const types = new Map<string, Test>([
].map(createDomElement) } ].map(createDomElement) }
], ],
['non-domElements', { ['non-domElements', {
is: value => !m.domElement(value), is: value => !is.domElement(value),
fixtures: [ fixtures: [
document.createTextNode('data'), document.createTextNode('data'),
document.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"'), document.createProcessingInstruction('xml-stylesheet', 'href="mycss.css" type="text/css"'),
@ -338,7 +338,7 @@ const types = new Map<string, Test>([
] ]
}], }],
['nodeStream', { ['nodeStream', {
is: m.nodeStream, is: is.nodeStream,
fixtures: [ fixtures: [
fs.createReadStream('readme.md'), fs.createReadStream('readme.md'),
fs.createWriteStream(tempy.file()), fs.createWriteStream(tempy.file()),
@ -352,7 +352,7 @@ const types = new Map<string, Test>([
] ]
}], }],
['observable', { ['observable', {
is: m.observable, is: is.observable,
fixtures: [ fixtures: [
new Observable(), new Observable(),
new Subject(), new Subject(),
@ -360,7 +360,7 @@ const types = new Map<string, Test>([
] ]
}], }],
['infinite', { ['infinite', {
is: m.infinite, is: is.infinite,
fixtures: [ fixtures: [
Infinity, Infinity,
-Infinity -Infinity
@ -378,7 +378,7 @@ const testType = (t: TestContext & Context<any>, type: string, exclude?: string[
return; return;
} }
const {is} = testData; const {is: testIs} = testData;
for (const [key, {fixtures}] of types) { for (const [key, {fixtures}] of types) {
// TODO: Automatically exclude value types in other tests that we have in the current one. // TODO: Automatically exclude value types in other tests that we have in the current one.
@ -390,14 +390,14 @@ const testType = (t: TestContext & Context<any>, type: string, exclude?: string[
const assert = key === type ? t.true.bind(t) : t.false.bind(t); const assert = key === type ? t.true.bind(t) : t.false.bind(t);
for (const fixture of fixtures) { for (const fixture of fixtures) {
assert(is(fixture), `Value: ${util.inspect(fixture)}`); assert(testIs(fixture), `Value: ${util.inspect(fixture)}`);
} }
} }
}; };
test('is', t => { test('is', t => {
t.is(m(null), 'null'); t.is(is(null), 'null');
t.is(m(undefined), 'undefined'); t.is(is(undefined), 'undefined');
// TODO: Expand this to all the supported types. Maybe reuse `testType()` somehow. // TODO: Expand this to all the supported types. Maybe reuse `testType()` somehow.
}); });
@ -435,7 +435,7 @@ test('is.function', t => {
}); });
test('is.boundFunction', t => { test('is.boundFunction', t => {
t.false(m.boundFunction(function () {})); // tslint:disable-line:no-empty only-arrow-functions t.false(is.boundFunction(function () {})); // tslint:disable-line:no-empty only-arrow-functions
}); });
test('is.buffer', t => { test('is.buffer', t => {
@ -452,7 +452,7 @@ test('is.object', t => {
} }
for (const el of testData.fixtures) { for (const el of testData.fixtures) {
t.true(m.object(el)); t.true(is.object(el));
} }
}); });
@ -554,36 +554,36 @@ test('is.directInstanceOf', t => {
const error = new Error(); const error = new Error();
const errorSubclass = new ErrorSubclassFixture(); const errorSubclass = new ErrorSubclassFixture();
t.true(m.directInstanceOf(error, Error)); t.true(is.directInstanceOf(error, Error));
t.true(m.directInstanceOf(errorSubclass, ErrorSubclassFixture)); t.true(is.directInstanceOf(errorSubclass, ErrorSubclassFixture));
t.false(m.directInstanceOf(error, ErrorSubclassFixture)); t.false(is.directInstanceOf(error, ErrorSubclassFixture));
t.false(m.directInstanceOf(errorSubclass, Error)); t.false(is.directInstanceOf(errorSubclass, Error));
}); });
test('is.urlInstance', t => { test('is.urlInstance', t => {
const url = new URL('https://www.example.com'); const url = new URL('https://www.example.com');
t.true(m.urlInstance(url)); t.true(is.urlInstance(url));
t.false(m.urlInstance({})); t.false(is.urlInstance({}));
t.false(m.urlInstance(undefined)); t.false(is.urlInstance(undefined));
t.false(m.urlInstance(null)); t.false(is.urlInstance(null));
}); });
test('is.truthy', t => { test('is.truthy', t => {
t.true(m.truthy('unicorn')); t.true(is.truthy('unicorn'));
t.true(m.truthy('🦄')); t.true(is.truthy('🦄'));
t.true(m.truthy(new Set())); t.true(is.truthy(new Set()));
t.true(m.truthy(Symbol('🦄'))); t.true(is.truthy(Symbol('🦄')));
t.true(m.truthy(true)); t.true(is.truthy(true));
}); });
test('is.falsy', t => { test('is.falsy', t => {
t.true(m.falsy(false)); t.true(is.falsy(false));
t.true(m.falsy(0)); t.true(is.falsy(0));
t.true(m.falsy('')); t.true(is.falsy(''));
t.true(m.falsy(null)); t.true(is.falsy(null));
t.true(m.falsy(undefined)); t.true(is.falsy(undefined));
t.true(m.falsy(NaN)); t.true(is.falsy(NaN));
}); });
test('is.nan', t => { test('is.nan', t => {
@ -608,19 +608,19 @@ test('is.primitive', t => {
]; ];
for (const el of primitives) { for (const el of primitives) {
t.true(m.primitive(el)); t.true(is.primitive(el));
} }
}); });
test('is.integer', t => { test('is.integer', t => {
testType(t, 'integer', ['number', 'safeInteger']); testType(t, 'integer', ['number', 'safeInteger']);
t.false(m.integer(1.4)); t.false(is.integer(1.4));
}); });
test('is.safeInteger', t => { test('is.safeInteger', t => {
testType(t, 'safeInteger', ['number', 'integer']); testType(t, 'safeInteger', ['number', 'integer']);
t.false(m.safeInteger(Math.pow(2, 53))); t.false(is.safeInteger(Math.pow(2, 53)));
t.false(m.safeInteger(-Math.pow(2, 53))); t.false(is.safeInteger(-Math.pow(2, 53)));
}); });
test('is.plainObject', t => { test('is.plainObject', t => {
@ -628,29 +628,29 @@ test('is.plainObject', t => {
}); });
test('is.iterable', t => { test('is.iterable', t => {
t.true(m.iterable('')); t.true(is.iterable(''));
t.true(m.iterable([])); t.true(is.iterable([]));
t.true(m.iterable(new Map())); t.true(is.iterable(new Map()));
t.false(m.iterable(null)); t.false(is.iterable(null));
t.false(m.iterable(undefined)); t.false(is.iterable(undefined));
t.false(m.iterable(0)); t.false(is.iterable(0));
t.false(m.iterable(NaN)); t.false(is.iterable(NaN));
t.false(m.iterable(Infinity)); t.false(is.iterable(Infinity));
t.false(m.iterable({})); t.false(is.iterable({}));
}); });
if (isNode10orHigher) { if (isNode10orHigher) {
test('is.asyncIterable', t => { test('is.asyncIterable', t => {
t.true(m.asyncIterable({ t.true(is.asyncIterable({
[Symbol.asyncIterator]: () => {} // tslint:disable-line:no-empty [Symbol.asyncIterator]: () => {} // tslint:disable-line:no-empty
})); }));
t.false(m.asyncIterable(null)); t.false(is.asyncIterable(null));
t.false(m.asyncIterable(undefined)); t.false(is.asyncIterable(undefined));
t.false(m.asyncIterable(0)); t.false(is.asyncIterable(0));
t.false(m.asyncIterable(NaN)); t.false(is.asyncIterable(NaN));
t.false(m.asyncIterable(Infinity)); t.false(is.asyncIterable(Infinity));
t.false(m.asyncIterable({})); t.false(is.asyncIterable({}));
}); });
} }
@ -662,7 +662,7 @@ test('is.class', t => {
]; ];
for (const x of classDeclarations) { for (const x of classDeclarations) {
t.true(m.class_(x)); t.true(is.class_(x));
} }
}); });
@ -680,61 +680,61 @@ test('is.typedArray', t => {
new Float64Array(0) new Float64Array(0)
]; ];
for (const el of typedArrays) { for (const item of typedArrays) {
t.true(m.typedArray(el)); t.true(is.typedArray(item));
} }
t.false(m.typedArray(new ArrayBuffer(1))); t.false(is.typedArray(new ArrayBuffer(1)));
t.false(m.typedArray([])); t.false(is.typedArray([]));
t.false(m.typedArray({})); t.false(is.typedArray({}));
}); });
test('is.arrayLike', t => { test('is.arrayLike', t => {
(function () { // tslint:disable-line:only-arrow-functions (function () { // tslint:disable-line:only-arrow-functions
t.true(m.arrayLike(arguments)); t.true(is.arrayLike(arguments));
})(); })();
t.true(m.arrayLike([])); t.true(is.arrayLike([]));
t.true(m.arrayLike('unicorn')); t.true(is.arrayLike('unicorn'));
t.false(m.arrayLike({})); t.false(is.arrayLike({}));
t.false(m.arrayLike(() => {})); // tslint:disable-line:no-empty t.false(is.arrayLike(() => {})); // tslint:disable-line:no-empty
t.false(m.arrayLike(new Map())); t.false(is.arrayLike(new Map()));
}); });
test('is.inRange', t => { test('is.inRange', t => {
const x = 3; const x = 3;
t.true(m.inRange(x, [0, 5])); t.true(is.inRange(x, [0, 5]));
t.true(m.inRange(x, [5, 0])); t.true(is.inRange(x, [5, 0]));
t.true(m.inRange(x, [-5, 5])); t.true(is.inRange(x, [-5, 5]));
t.true(m.inRange(x, [5, -5])); t.true(is.inRange(x, [5, -5]));
t.false(m.inRange(x, [4, 8])); t.false(is.inRange(x, [4, 8]));
t.true(m.inRange(-7, [-5, -10])); t.true(is.inRange(-7, [-5, -10]));
t.true(m.inRange(-5, [-5, -10])); t.true(is.inRange(-5, [-5, -10]));
t.true(m.inRange(-10, [-5, -10])); t.true(is.inRange(-10, [-5, -10]));
t.true(m.inRange(x, 10)); t.true(is.inRange(x, 10));
t.true(m.inRange(0, 0)); t.true(is.inRange(0, 0));
t.true(m.inRange(-2, -3)); t.true(is.inRange(-2, -3));
t.false(m.inRange(x, 2)); t.false(is.inRange(x, 2));
t.false(m.inRange(-3, -2)); t.false(is.inRange(-3, -2));
t.throws(() => { t.throws(() => {
m.inRange(0, []); is.inRange(0, []);
}); });
t.throws(() => { t.throws(() => {
m.inRange(0, [5]); is.inRange(0, [5]);
}); });
t.throws(() => { t.throws(() => {
m.inRange(0, [1, 2, 3]); is.inRange(0, [1, 2, 3]);
}); });
}); });
test('is.domElement', t => { test('is.domElement', t => {
testType(t, 'domElement'); testType(t, 'domElement');
t.false(m.domElement({nodeType: 1, nodeName: 'div'})); t.false(is.domElement({nodeType: 1, nodeName: 'div'}));
}); });
test('is.nodeStream', t => { test('is.nodeStream', t => {
@ -747,21 +747,21 @@ test('is.infinite', t => {
test('is.even', t => { test('is.even', t => {
for (const el of [-6, 2, 4]) { for (const el of [-6, 2, 4]) {
t.true(m.even(el)); t.true(is.even(el));
} }
for (const el of [-3, 1, 5]) { for (const el of [-3, 1, 5]) {
t.false(m.even(el)); t.false(is.even(el));
} }
}); });
test('is.odd', t => { test('is.odd', t => {
for (const el of [-5, 7, 13]) { for (const el of [-5, 7, 13]) {
t.true(m.odd(el)); t.true(is.odd(el));
} }
for (const el of [-8, 8, 10]) { for (const el of [-8, 8, 10]) {
t.false(m.odd(el)); t.false(is.odd(el));
} }
}); });
@ -770,39 +770,42 @@ test('is.emptyArray', t => {
}); });
test('is.nonEmptyArray', t => { test('is.nonEmptyArray', t => {
t.true(m.nonEmptyArray([1, 2, 3])); t.true(is.nonEmptyArray([1, 2, 3]));
t.false(m.nonEmptyArray([])); t.false(is.nonEmptyArray([]));
t.false(m.nonEmptyArray(new Array())); t.false(is.nonEmptyArray(new Array()));
}); });
test('is.emptyString', t => { test('is.emptyString', t => {
testType(t, 'emptyString', ['string']); testType(t, 'emptyString', ['string']);
t.false(m.emptyString('🦄')); t.false(is.emptyString('🦄'));
}); });
test('is.nonEmptyString', t => { test('is.nonEmptyString', t => {
t.false(m.nonEmptyString('')); t.false(is.nonEmptyString(''));
t.false(m.nonEmptyString(String())); t.false(is.nonEmptyString(String()));
t.true(m.nonEmptyString('🦄')); t.true(is.nonEmptyString('🦄'));
}); });
test('is.emptyStringOrWhitespace', t => { test('is.emptyStringOrWhitespace', t => {
testType(t, 'emptyString', ['string']); testType(t, 'emptyString', ['string']);
t.true(m.emptyStringOrWhitespace(' ')); t.true(is.emptyStringOrWhitespace(' '));
t.false(m.emptyStringOrWhitespace('🦄')); t.false(is.emptyStringOrWhitespace('🦄'));
t.false(m.emptyStringOrWhitespace('unicorn')); t.false(is.emptyStringOrWhitespace('unicorn'));
}); });
test('is.emptyObject', t => { test('is.emptyObject', t => {
t.true(m.emptyObject({})); t.true(is.emptyObject({}));
t.true(m.emptyObject(new Object())); t.true(is.emptyObject(new Object()));
t.false(m.emptyObject({unicorn: '🦄'})); t.false(is.emptyObject({unicorn: '🦄'}));
}); });
test('is.nonEmptyObject', t => { test('is.nonEmptyObject', t => {
t.false(m.nonEmptyObject({})); const foo = {};
t.false(m.nonEmptyObject(new Object())); is.nonEmptyObject(foo);
t.true(m.nonEmptyObject({unicorn: '🦄'}));
t.false(is.nonEmptyObject({}));
t.false(is.nonEmptyObject(new Object()));
t.true(is.nonEmptyObject({unicorn: '🦄'}));
}); });
test('is.emptySet', t => { test('is.emptySet', t => {
@ -811,10 +814,10 @@ test('is.emptySet', t => {
test('is.nonEmptySet', t => { test('is.nonEmptySet', t => {
const tempSet = new Set(); const tempSet = new Set();
t.false(m.nonEmptySet(tempSet)); t.false(is.nonEmptySet(tempSet));
tempSet.add(1); tempSet.add(1);
t.true(m.nonEmptySet(tempSet)); t.true(is.nonEmptySet(tempSet));
}); });
test('is.emptyMap', t => { test('is.emptyMap', t => {
@ -823,38 +826,38 @@ test('is.emptyMap', t => {
test('is.nonEmptyMap', t => { test('is.nonEmptyMap', t => {
const tempMap = new Map(); const tempMap = new Map();
t.false(m.nonEmptyMap(tempMap)); t.false(is.nonEmptyMap(tempMap));
tempMap.set('unicorn', '🦄'); tempMap.set('unicorn', '🦄');
t.true(m.nonEmptyMap(tempMap)); t.true(is.nonEmptyMap(tempMap));
}); });
test('is.any', t => { test('is.any', t => {
t.true(m.any(m.string, {}, true, '🦄')); t.true(is.any(is.string, {}, true, '🦄'));
t.true(m.any(m.object, false, {}, 'unicorns')); t.true(is.any(is.object, false, {}, 'unicorns'));
t.false(m.any(m.boolean, '🦄', [], 3)); t.false(is.any(is.boolean, '🦄', [], 3));
t.false(m.any(m.integer, true, 'lol', {})); t.false(is.any(is.integer, true, 'lol', {}));
t.throws(() => { t.throws(() => {
m.any(null, true); is.any(null, true);
}); });
t.throws(() => { t.throws(() => {
m.any(m.string); is.any(is.string);
}); });
}); });
test('is.all', t => { test('is.all', t => {
t.true(m.all(m.object, {}, new Set(), new Map())); t.true(is.all(is.object, {}, new Set(), new Map()));
t.true(m.all(m.boolean, true, false)); t.true(is.all(is.boolean, true, false));
t.false(m.all(m.string, '🦄', [])); t.false(is.all(is.string, '🦄', []));
t.false(m.all(m.set, new Map(), {})); t.false(is.all(is.set, new Map(), {}));
t.throws(() => { t.throws(() => {
m.all(null, true); is.all(null, true);
}); });
t.throws(() => { t.throws(() => {
m.all(m.string); is.all(is.string);
}); });
}); });