Sha256: f3cb4782821455782d894a49e64ab07b6644a56aa439e60b67f7e206ef055669

Contents?: true

Size: 1.59 KB

Versions: 41

Compression:

Stored size: 1.59 KB

Contents

'use strict';

var test = require('tape');
var isBoolean = require('../');
var hasToStringTag = require('has-tostringtag/shams')();

test('not Booleans', function (t) {
	t.test('primitives', function (st) {
		st.notOk(isBoolean(), 'undefined is not Boolean');
		st.notOk(isBoolean(null), 'null is not Boolean');
		st.notOk(isBoolean(0), '0 is not Boolean');
		st.notOk(isBoolean(NaN), 'NaN is not Boolean');
		st.notOk(isBoolean(Infinity), 'Infinity is not Boolean');
		st.notOk(isBoolean('foo'), 'string is not Boolean');
		st.end();
	});

	t.test('objects', function (st) {
		st.notOk(isBoolean(Object(42)), 'number object is not Boolean');
		st.notOk(isBoolean([]), 'array is not Boolean');
		st.notOk(isBoolean({}), 'object is not Boolean');
		st.notOk(isBoolean(function () {}), 'function is not Boolean');
		st.notOk(isBoolean(/a/g), 'regex literal is not Boolean');
		st.notOk(isBoolean(new RegExp('a', 'g')), 'regex object is not Boolean');
		st.notOk(isBoolean(new Date()), 'new Date() is not Boolean');
		st.end();
	});

	t.end();
});

test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
	var fakeBoolean = {
		toString: function () { return 'true'; },
		valueOf: function () { return true; }
	};
	fakeBoolean[Symbol.toStringTag] = 'Boolean';
	t.notOk(isBoolean(fakeBoolean), 'fake Boolean with @@toStringTag "Boolean" is not Boolean');
	t.end();
});

test('Booleans', function (t) {
	t.ok(isBoolean(true), 'true is Boolean');
	t.ok(isBoolean(false), 'false is Boolean');
	t.ok(isBoolean(Object(true)), 'Object(true) is Boolean');
	t.ok(isBoolean(Object(false)), 'Object(false) is Boolean');
	t.end();
});

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
immosquare-cleaner-0.1.51 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.50 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.49 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.48 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.47 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.46 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.45 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.44 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.43 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.42 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.41 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.40 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.39 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.38 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.32 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.31 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.30 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.29 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.28 node_modules/is-boolean-object/test/index.js
immosquare-cleaner-0.1.27 node_modules/is-boolean-object/test/index.js