Make the is() function type-safe (#117)

This commit is contained in:
Bjorn Stromberg 2020-06-28 05:20:36 +09:00 committed by GitHub
parent a96abee1a3
commit 71ca1e5573
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 13 deletions

View file

@ -1275,18 +1275,18 @@ test('is.domElement', t => {
assert.domElement({nodeType: 1, nodeName: 'div'});
});
const htmlTagNameToTypeName = {
div: 'HTMLDivElement',
input: 'HTMLInputElement',
span: 'HTMLSpanElement',
img: 'HTMLImageElement',
canvas: 'HTMLCanvasElement',
script: 'HTMLScriptElement'
};
const tagNames = [
'div',
'input',
'span',
'img',
'canvas',
'script'
];
for (const [tagName, typeName] of Object.entries(htmlTagNameToTypeName)) {
for (const tagName of tagNames) {
const domElement = createDomElement(tagName);
t.is(is(domElement), typeName);
t.is(is(domElement), 'HTMLElement');
}
});