chore(test): fix tests for string object children

pull/983/head
Jan van Brügge 4 years ago
parent 19d1d29260
commit d6d0cfce8c
No known key found for this signature in database
GPG Key ID: 88E0BF7B7A546481

@ -32,6 +32,7 @@ module.exports = {
"@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-types": "off",
}, },
}, },
{ {

@ -2,7 +2,14 @@ import { vnode, VNode, VNodeData } from "./vnode";
import * as is from "./is"; import * as is from "./is";
export type VNodes = VNode[]; export type VNodes = VNode[];
export type VNodeChildElement = VNode | string | number | undefined | null; export type VNodeChildElement =
| VNode
| string
| number
| String
| Number
| undefined
| null;
export type ArrayOrElement<T> = T | T[]; export type ArrayOrElement<T> = T | T[];
export type VNodeChildren = ArrayOrElement<VNodeChildElement>; export type VNodeChildren = ArrayOrElement<VNodeChildElement>;

@ -86,20 +86,16 @@ describe("snabbdom", function () {
const vnode = h("a", {}, "I am a string"); const vnode = h("a", {}, "I am a string");
assert.strictEqual(vnode.text, "I am a string"); assert.strictEqual(vnode.text, "I am a string");
}); });
it("can create vnode with String obj content", function() { it("can create vnode with String obj content", function () {
var vnode = h("a", new String("b")); const vnode = h("a", new String("b"));
assert.equal(vnode.text, "b"); assert.equal(vnode.text, "b");
}); });
it("can create vnode with props and String obj content", function() { it("can create vnode with props and String obj content", function () {
var vnode = h("a", {}, new String("b")); const vnode = h("a", {}, new String("b"));
assert.equal(vnode.text, "b"); assert.equal(vnode.text, "b");
}); });
it("can create vnode with array String obj content", function() { it("can create vnode with Number obj content", function () {
var vnode = h("a", ["b", new String("c")]); const vnode = h("a", new Number(1));
assert.equal(vnode.text, "bc");
});
it("can create vnode with Number obj content", function() {
var vnode = h("a", new Number(1));
assert.equal(vnode.text, "1"); assert.equal(vnode.text, "1");
}); });
it("can create vnode with null props", function () { it("can create vnode with null props", function () {
@ -206,8 +202,10 @@ describe("snabbdom", function () {
} }
}); });
it("handles classes from both selector and property", function () { it("handles classes from both selector and property", function () {
elm = patch(vnode0, h("div", [h("i.has", { class: { classes: true } })])) elm = patch(
.elm; vnode0,
h("div", [h("i.has", { class: { classes: true } })])
).elm;
assert(elm.firstChild.classList.contains("has"), "has `has` class"); assert(elm.firstChild.classList.contains("has"), "has `has` class");
assert( assert(
elm.firstChild.classList.contains("classes"), elm.firstChild.classList.contains("classes"),
@ -223,6 +221,10 @@ describe("snabbdom", function () {
assert.strictEqual(elm.childNodes[0].tagName, "SPAN"); assert.strictEqual(elm.childNodes[0].tagName, "SPAN");
assert.strictEqual(elm.childNodes[1].textContent, "I am a string"); assert.strictEqual(elm.childNodes[1].textContent, "I am a string");
}); });
it("can create vnode with array String obj content", function () {
elm = patch(vnode0, h("a", ["b", new String("c")])).elm;
assert.strictEqual(elm.innerHTML, "bc");
});
it("can create elements with props", function () { it("can create elements with props", function () {
elm = patch(vnode0, h("a", { props: { src: "http://localhost/" } })).elm; elm = patch(vnode0, h("a", { props: { src: "http://localhost/" } })).elm;
assert.strictEqual(elm.src, "http://localhost/"); assert.strictEqual(elm.src, "http://localhost/");
@ -809,9 +811,8 @@ describe("snabbdom", function () {
}) })
); );
const shufArr = shuffle(arr.slice(0)); const shufArr = shuffle(arr.slice(0));
let elm: HTMLDivElement | HTMLSpanElement = document.createElement( let elm: HTMLDivElement | HTMLSpanElement =
"div" document.createElement("div");
);
elm = patch(elm, vnode1).elm as HTMLSpanElement; elm = patch(elm, vnode1).elm as HTMLSpanElement;
for (i = 0; i < elms; ++i) { for (i = 0; i < elms; ++i) {
assert.strictEqual(elm.children[i].innerHTML, i.toString()); assert.strictEqual(elm.children[i].innerHTML, i.toString());

Loading…
Cancel
Save