source: imaps-frontend/node_modules/is-boolean-object/test/index.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.7 KB
Line 
1'use strict';
2
3var test = require('tape');
4var isBoolean = require('../');
5var hasToStringTag = require('has-tostringtag/shams')();
6
7test('not Booleans', function (t) {
8 t.test('primitives', function (st) {
9 // @ts-expect-error
10 st.notOk(isBoolean(), 'undefined is not Boolean');
11 st.notOk(isBoolean(null), 'null is not Boolean');
12 st.notOk(isBoolean(0), '0 is not Boolean');
13 st.notOk(isBoolean(NaN), 'NaN is not Boolean');
14 st.notOk(isBoolean(Infinity), 'Infinity is not Boolean');
15 st.notOk(isBoolean('foo'), 'string is not Boolean');
16 st.end();
17 });
18
19 t.test('objects', function (st) {
20 st.notOk(isBoolean(Object(42)), 'number object is not Boolean');
21 st.notOk(isBoolean([]), 'array is not Boolean');
22 st.notOk(isBoolean({}), 'object is not Boolean');
23 st.notOk(isBoolean(function () {}), 'function is not Boolean');
24 st.notOk(isBoolean(/a/g), 'regex literal is not Boolean');
25 st.notOk(isBoolean(new RegExp('a', 'g')), 'regex object is not Boolean');
26 st.notOk(isBoolean(new Date()), 'new Date() is not Boolean');
27 st.end();
28 });
29
30 t.end();
31});
32
33test('@@toStringTag', { skip: !hasToStringTag }, function (t) {
34 /** @type {{ toString(): unknown; valueOf(): unknown; [Symbol.toStringTag]?: string; }} */
35 var fakeBoolean = {
36 toString: function () { return 'true'; },
37 valueOf: function () { return true; }
38 };
39 fakeBoolean[Symbol.toStringTag] = 'Boolean';
40 t.notOk(isBoolean(fakeBoolean), 'fake Boolean with @@toStringTag "Boolean" is not Boolean');
41 t.end();
42});
43
44test('Booleans', function (t) {
45 t.ok(isBoolean(true), 'true is Boolean');
46 t.ok(isBoolean(false), 'false is Boolean');
47 t.ok(isBoolean(Object(true)), 'Object(true) is Boolean');
48 t.ok(isBoolean(Object(false)), 'Object(false) is Boolean');
49 t.end();
50});
Note: See TracBrowser for help on using the repository browser.