Skip to content

Commit 6f987e4

Browse files
committed
test page column order, fix number types
1 parent 3e6fa0e commit 6f987e4

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

isType.mjs.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,18 @@ class TypeTest {
6969
this[name] = typeName === name;
7070
}
7171

72+
this.object = value instanceof Object;
73+
this.primitive = !this.object;
74+
this.objectish = this.object || this.null;
75+
7276
this.numberish = this.number || this.nan;
7377
if(this.number){
7478
this.real = Number.isFinite(this.object ? value.valueOf() : value);
7579
this.infinite = !this.real;
7680
}
77-
78-
this.object = value instanceof Object;
79-
this.primitive = !this.object;
80-
this.objectish = this.object || this.null;
81+
else{
82+
this.real = this.infinite = false;
83+
}
8184

8285
this.defined = !this.undefined;
8386
this.nullish = this.undefined || this.null;

test/test.js

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,42 @@
11
import is from "../isType.mjs.js";
22

3+
window.is = is;
4+
5+
const COLUMNS = [
6+
"defined",
7+
"undefined",
8+
"primitive",
9+
"object",
10+
"objectish",
11+
"null",
12+
"nullish",
13+
"boolean",
14+
"false",
15+
"true",
16+
"falsy",
17+
"truthy",
18+
"symbol",
19+
"bigint",
20+
"numberish",
21+
"nan",
22+
"number",
23+
"real",
24+
"infinite",
25+
"string",
26+
"array",
27+
"map",
28+
"set",
29+
"weakmap",
30+
"weakset",
31+
"empty",
32+
"nonempty",
33+
"date",
34+
"error",
35+
"function",
36+
"promise",
37+
"regex",
38+
];
39+
340
let testResults = [];
441

542
{
@@ -8,24 +45,25 @@ let testResults = [];
845
_is(()=>(false), is.boolean, is.defined, is.primitive, is.false, is.falsy);
946
_is(()=>(true), is.boolean, is.defined, is.primitive, is.true, is.truthy);
1047
_is(()=>(new Boolean(false)), is.object, is.defined, is.objectish, is.truthy);
48+
_is(()=>(Symbol()), is.symbol, is.defined, is.primitive, is.truthy);
49+
_is(()=>(Symbol.toStringTag), is.symbol, is.defined, is.primitive, is.truthy);
1150
_is(()=>(0n), is.bigint, is.defined, is.primitive, is.falsy);
1251
_is(()=>(5n), is.bigint, is.defined, is.primitive, is.truthy);
52+
_is(()=>(NaN), is.nan, is.defined, is.primitive, is.falsy, is.numberish);
53+
_is(()=>(+"a"), is.nan, is.defined, is.primitive, is.falsy, is.numberish);
54+
_is(()=>(new Number(NaN)), is.nan, is.defined, is.object, is.objectish, is.truthy, is.numberish);
55+
_is(()=>(new Number("a")), is.nan, is.defined, is.object, is.objectish, is.truthy, is.numberish);
1356
_is(()=>(0), is.number, is.defined, is.primitive, is.falsy, is.real, is.numberish);
1457
_is(()=>(5), is.number, is.defined, is.primitive, is.truthy, is.real, is.numberish);
1558
_is(()=>(new Number(0)), is.number, is.defined, is.object, is.objectish, is.truthy, is.real, is.numberish);
1659
_is(()=>(new Number(5)), is.number, is.defined, is.object, is.objectish, is.truthy, is.real, is.numberish);
1760
_is(()=>(Infinity), is.number, is.defined, is.primitive, is.truthy, is.infinite, is.numberish);
1861
_is(()=>(-1/0), is.number, is.defined, is.primitive, is.truthy, is.infinite, is.numberish);
1962
_is(()=>(new Number(Infinity)), is.number, is.defined, is.object, is.objectish, is.truthy, is.infinite, is.numberish);
20-
_is(()=>(NaN), is.nan, is.defined, is.primitive, is.falsy, is.numberish);
21-
_is(()=>(+"a"), is.nan, is.defined, is.primitive, is.falsy, is.numberish);
22-
_is(()=>(new Number(NaN)), is.nan, is.defined, is.object, is.objectish, is.truthy, is.numberish);
23-
_is(()=>(new Number("a")), is.nan, is.defined, is.object, is.objectish, is.truthy, is.numberish);
2463
_is(()=>(""), is.string, is.defined, is.primitive, is.falsy, is.empty);
2564
_is(()=>("a"), is.string, is.defined, is.primitive, is.truthy, is.nonempty);
2665
_is(()=>(new String("")), is.string, is.defined, is.object, is.objectish, is.truthy, is.empty);
2766
_is(()=>(new String("a")), is.string, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
28-
_is(()=>(Symbol()), is.symbol, is.defined, is.primitive, is.truthy);
2967
_is(()=>([]), is.array, is.defined, is.object, is.objectish, is.truthy, is.empty);
3068
_is(()=>([1,2]), is.array, is.defined, is.object, is.objectish, is.truthy, is.nonempty);
3169
_is(()=>(new Array()), is.array, is.defined, is.object, is.objectish, is.truthy, is.empty);
@@ -51,8 +89,6 @@ let testResults = [];
5189
_is(()=>(/*class A{}*/ new A()), is.object, is.defined, is.objectish, is.truthy);
5290
class B extends String{}
5391
_is(()=>(/*class B extends String{}*/ new B()), is.string, is.defined, is.object, is.objectish, is.truthy, is.empty);
54-
class C { get [Symbol.toStringTag](){ return "D"; } }
55-
_is(()=>(/*class C {get [Symbol.toStringTag](){return "D"}}*/ new C()), is.object, is.defined, is.objectish, is.truthy);
5692

5793
}
5894

@@ -100,17 +136,17 @@ function _is(fn, type, ...trues){
100136
*/
101137
function createTableContent(){
102138

139+
let header = "<th></th><th><div>type</div></th>";
140+
for(const propName of COLUMNS){
141+
header += `<th><div>${propName}</div></th>`;
142+
}
143+
103144
let rows = "";
104145
for(const result of testResults){
105146
rows += createRow(result);
106147
}
107148

108-
let header = "<th></th><th><div>type</div></th>";
109-
for(const propName in is){
110-
header += `<th><div>${propName}</div></th>`;
111-
}
112-
113-
return `<thead><tr>${header}</tr></thead><tbody>${rows}</tbody>`;
149+
return `<thead style="position:sticky;top:0;background:#FFF;"><tr>${header}</tr></thead><tbody>${rows}</tbody>`;
114150
}
115151

116152
/**
@@ -128,7 +164,7 @@ function createRow(result){
128164
if(!typeMatch) cells += `<br>(expected ${result.type.expected})`;
129165
cells += `</td>`;
130166

131-
for(const prop in result.properties){
167+
for(const prop of COLUMNS){
132168
cells += createCell(result.properties[prop].expected, result.properties[prop].actual);
133169
}
134170

0 commit comments

Comments
 (0)