chore(test): chai assert & karma-mocha-reporter (#541)

Closes #535.
pull/542/head
Shahar Dawn Or 5 years ago committed by GitHub
parent 97a8d50013
commit 8055d395f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -22,6 +22,7 @@ module.exports = function (config) {
files: [{ pattern: 'src/**/*' }],
plugins: [
'karma-mocha',
require('karma-mocha-reporter'),
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-browserstack-launcher',
@ -53,7 +54,10 @@ module.exports = function (config) {
values: ['src/test/**/*'],
},
},
reporters: ['dots', 'karma-typescript', 'BrowserStack'],
reporters: ['mocha', 'karma-typescript', 'BrowserStack'],
mochaReporter: {
showDiff: true
},
port: 9876,
colors: true,
autoWatch: true,

168
package-lock.json generated

@ -684,6 +684,12 @@
"integrity": "sha512-491hfOvNr0+BGOHT2m36xJ+LK68IuOshvxV0VIrKOnzBDL11WlDa3PwO+drTYkwCdfzJRN9REcDPZVVcrx1ucw==",
"dev": true
},
"@types/chai": {
"version": "4.2.7",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.2.7.tgz",
"integrity": "sha512-luq8meHGYwvky0O7u0eQZdA7B4Wd9owUCqvbw2m3XCrCU8mplYOujMBbvyS547AxJkC+pGnd0Cm15eNxEUNU8g==",
"dev": true
},
"@types/eslint-visitor-keys": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz",
@ -1171,6 +1177,12 @@
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=",
"dev": true
},
"assertion-error": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==",
"dev": true
},
"assign-symbols": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/assign-symbols/-/assign-symbols-1.0.0.tgz",
@ -1824,6 +1836,20 @@
"integrity": "sha512-fpZ81yYfzentuieinmGnphk0pLkOTMm6MZdVqwd77ROvhko6iujLNGrHH5E7utq3ygWklwfmwuG+A7P+NpqT6w==",
"dev": true
},
"chai": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
"dev": true,
"requires": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
"deep-eql": "^3.0.1",
"get-func-name": "^2.0.0",
"pathval": "^1.1.0",
"type-detect": "^4.0.5"
}
},
"chainsaw": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/chainsaw/-/chainsaw-0.1.0.tgz",
@ -1876,6 +1902,12 @@
"integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
"dev": true
},
"check-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
"dev": true
},
"chokidar": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.5.tgz",
@ -2659,6 +2691,15 @@
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
"dev": true
},
"deep-eql": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
"dev": true,
"requires": {
"type-detect": "^4.0.0"
}
},
"deep-extend": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz",
@ -4786,6 +4827,12 @@
"integrity": "sha512-mBBwmeGTrxEMO4pMaaf/uUEFHnYtwr8FTe8Y/mer4rcV/bye0qGm6pw1bGZFGStxC5O76c5ZAVBGnqHmOaJpdQ==",
"dev": true
},
"get-func-name": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
"dev": true
},
"get-stdin": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-4.0.1.tgz",
@ -6842,6 +6889,69 @@
"minimist": "1.2.0"
}
},
"karma-mocha-reporter": {
"version": "2.2.5",
"resolved": "https://registry.npmjs.org/karma-mocha-reporter/-/karma-mocha-reporter-2.2.5.tgz",
"integrity": "sha1-FRIAlejtgZGG5HoLAS8810GJVWA=",
"dev": true,
"requires": {
"chalk": "^2.1.0",
"log-symbols": "^2.1.0",
"strip-ansi": "^4.0.0"
},
"dependencies": {
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
}
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"karma-typescript": {
"version": "3.0.13",
"resolved": "https://registry.npmjs.org/karma-typescript/-/karma-typescript-3.0.13.tgz",
@ -7401,6 +7511,52 @@
}
}
},
"log-symbols": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz",
"integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==",
"dev": true,
"requires": {
"chalk": "^2.0.1"
},
"dependencies": {
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": {
"color-convert": "^1.9.0"
}
},
"chalk": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": {
"ansi-styles": "^3.2.1",
"escape-string-regexp": "^1.0.5",
"supports-color": "^5.3.0"
}
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=",
"dev": true
},
"supports-color": {
"version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": {
"has-flag": "^3.0.0"
}
}
}
},
"log4js": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/log4js/-/log4js-3.0.6.tgz",
@ -8621,6 +8777,12 @@
}
}
},
"pathval": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
"dev": true
},
"pbkdf2": {
"version": "3.0.17",
"resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz",
@ -10429,6 +10591,12 @@
"prelude-ls": "~1.1.2"
}
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==",
"dev": true
},
"type-fest": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz",

@ -14,11 +14,13 @@
"@commitlint/config-conventional": "^8.2.0",
"@commitlint/travis-cli": "^8.2.0",
"@types/assert": "^1.4.3",
"@types/chai": "^4.2.7",
"@types/lodash.shuffle": "^4.2.6",
"@types/mocha": "^5.2.7",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"benchmark": "^2.1.4",
"browserify": "^14.4.0",
"chai": "^4.2.0",
"editorconfig-checker": "^3.0.3",
"eslint": "^6.7.2",
"eslint-config-standard-with-typescript": "^11.0.1",
@ -37,6 +39,7 @@
"karma-chrome-launcher": "^2.2.0",
"karma-firefox-launcher": "^1.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-typescript": "^3.0.13",
"lodash.shuffle": "^4.2.0",
"mocha": "^5.2.0",

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import { init } from '../snabbdom'
import { RemoveHook } from '../hooks';
import attachTo from '../helpers/attachto'

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import { init } from '../snabbdom'
import attributesModule from '../modules/attributes'
import h from '../h'

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import shuffle from 'lodash.shuffle'
import { init } from '../snabbdom'
@ -78,7 +78,7 @@ describe('snabbdom', function () {
});
it('can create vnode with null props', function () {
var vnode = h('a', null);
assert.deepStrictEqual(vnode.data, {});
assert.deepEqual(vnode.data, {});
vnode = h('a', null, ['I am a string']);
const children = vnode.children as [VNode]
assert.strictEqual(children[0].text, 'I am a string');
@ -373,10 +373,10 @@ describe('snabbdom', function () {
elm.appendChild(text);
var vnode = toVNode(elm, domApi);
assert.strictEqual(vnode.sel, 'x-div#id.class.other');
assert.deepStrictEqual(vnode.data, { attrs: { data: 'value' } });
assert.deepEqual(vnode.data, { attrs: { data: 'value' } });
const children = vnode.children as [VNode, VNode]
assert.strictEqual(children[0].sel, 'x-h2#hx');
assert.deepStrictEqual(children[0].data, { attrs: { 'data-env': 'xyz' } });
assert.deepEqual(children[0].data, { attrs: { 'data-env': 'xyz' } });
assert.strictEqual(children[1].text, 'Foobar');
});
});
@ -407,7 +407,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 2);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3', '4', '5']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3', '4', '5']);
});
it('add elements in the middle', function () {
var vnode1 = h('span', [1, 2, 4, 5].map(spanNum));
@ -416,7 +416,7 @@ describe('snabbdom', function () {
assert.strictEqual(elm.children.length, 4);
assert.strictEqual(elm.children.length, 4);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3', '4', '5']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3', '4', '5']);
});
it('add elements at begin and end', function () {
var vnode1 = h('span', [2, 3, 4].map(spanNum));
@ -424,7 +424,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 3);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3', '4', '5']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3', '4', '5']);
});
it('adds children to parent with no children', function () {
var vnode1 = h('span', { key: 'span' });
@ -432,13 +432,13 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 0);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3']);
});
it('removes all children from parent', function () {
var vnode1 = h('span', { key: 'span' }, [1, 2, 3].map(spanNum));
var vnode2 = h('span', { key: 'span' });
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3']);
elm = patch(vnode1, vnode2).elm;
assert.strictEqual(elm.children.length, 0);
});
@ -446,9 +446,9 @@ describe('snabbdom', function () {
var vnode1 = h('span', { key: 'span' }, [1, 2, 3].map(spanNum));
var vnode2 = h('span', { key: 'span' }, [spanNum(1), h('i', { key: 2 }, '2'), spanNum(3)]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2', '3']);
assert.deepEqual(map(inner, elm.children), ['1', '2', '3']);
assert.strictEqual(elm.children.length, 3);
assert.strictEqual(elm.children[1].tagName, 'I');
});
@ -460,7 +460,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 5);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['3', '4', '5']);
assert.deepEqual(map(inner, elm.children), ['3', '4', '5']);
});
it('removes elements from the end', function () {
var vnode1 = h('span', [1, 2, 3, 4, 5].map(spanNum));
@ -480,7 +480,7 @@ describe('snabbdom', function () {
assert.strictEqual(elm.children.length, 5);
elm = patch(vnode1, vnode2).elm;
assert.strictEqual(elm.children.length, 4);
assert.deepStrictEqual(elm.children[0].innerHTML, '1');
assert.deepEqual(elm.children[0].innerHTML, '1');
assert.strictEqual(elm.children[0].innerHTML, '1');
assert.strictEqual(elm.children[1].innerHTML, '2');
assert.strictEqual(elm.children[2].innerHTML, '4');
@ -556,7 +556,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 3);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['4', '6']);
assert.deepEqual(map(inner, elm.children), ['4', '6']);
});
it('handles moved and set to undefined element ending at the end', function () {
var vnode1 = h('span', [2, 4, 5].map(spanNum));
@ -586,7 +586,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 8);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['8', '7', '6', '5', '4', '3', '2', '1']);
assert.deepEqual(map(inner, elm.children), ['8', '7', '6', '5', '4', '3', '2', '1']);
});
it('something', function () {
var vnode1 = h('span', [0, 1, 2, 3, 4, 5].map(spanNum));
@ -594,7 +594,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 6);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['4', '3', '2', '1', '5', '0']);
assert.deepEqual(map(inner, elm.children), ['4', '3', '2', '1', '5', '0']);
});
it('handles random shuffles', function () {
var n, i, arr = [], opacities: string[] = [], elms = 14, samples = 5;
@ -630,7 +630,7 @@ describe('snabbdom', function () {
elm = patch(vnode0, vnode1).elm;
assert.strictEqual(elm.children.length, 6);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['2', '1', '0', '5', '4', '3']);
assert.deepEqual(map(inner, elm.children), ['2', '1', '0', '5', '4', '3']);
});
it('supports all null/undefined children', function () {
var vnode1 = h('i', [0, 1, 2, 3, 4, 5].map(spanNum));
@ -640,7 +640,7 @@ describe('snabbdom', function () {
elm = patch(vnode1, vnode2).elm;
assert.strictEqual(elm.children.length, 0);
elm = patch(vnode2, vnode3).elm;
assert.deepStrictEqual(map(inner, elm.children), ['5', '4', '3', '2', '1', '0']);
assert.deepEqual(map(inner, elm.children), ['5', '4', '3', '2', '1', '0']);
});
it('handles random shuffles with null/undefined children', function () {
var i, j, r, len, arr, maxArrLen = 15, samples = 5, vnode1 = vnode0, vnode2;
@ -655,7 +655,7 @@ describe('snabbdom', function () {
shuffle(arr);
vnode2 = h('div', arr.map(spanNum));
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), arr.filter(function (x) { return x != null; }));
assert.deepEqual(map(inner, elm.children), arr.filter(function (x) { return x != null; }));
}
});
});
@ -664,9 +664,9 @@ describe('snabbdom', function () {
var vnode1 = h('div', [h('span', 'Hello')]);
var vnode2 = h('div', [h('span', 'Hello'), h('span', 'World')]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['Hello']);
assert.deepEqual(map(inner, elm.children), ['Hello']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['Hello', 'World']);
assert.deepEqual(map(inner, elm.children), ['Hello', 'World']);
});
it('handles unmoved text nodes', function () {
var vnode1 = h('div', ['Text', h('span', 'Span')]);
@ -712,26 +712,26 @@ describe('snabbdom', function () {
var vnode1 = h('div', [h('span', 'World')]);
var vnode2 = h('div', [h('span', 'Hello'), h('span', 'World')]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['World']);
assert.deepEqual(map(inner, elm.children), ['World']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['Hello', 'World']);
assert.deepEqual(map(inner, elm.children), ['Hello', 'World']);
});
it('prepends element of different tag type', function () {
var vnode1 = h('div', [h('span', 'World')]);
var vnode2 = h('div', [h('div', 'Hello'), h('span', 'World')]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['World']);
assert.deepEqual(map(inner, elm.children), ['World']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(prop('tagName'), elm.children), ['DIV', 'SPAN']);
assert.deepStrictEqual(map(inner, elm.children), ['Hello', 'World']);
assert.deepEqual(map(prop('tagName'), elm.children), ['DIV', 'SPAN']);
assert.deepEqual(map(inner, elm.children), ['Hello', 'World']);
});
it('removes elements', function () {
var vnode1 = h('div', [h('span', 'One'), h('span', 'Two'), h('span', 'Three')]);
var vnode2 = h('div', [h('span', 'One'), h('span', 'Three')]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['One', 'Two', 'Three']);
assert.deepEqual(map(inner, elm.children), ['One', 'Two', 'Three']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['One', 'Three']);
assert.deepEqual(map(inner, elm.children), ['One', 'Three']);
});
it('removes a single text node', function () {
var vnode1 = h('div', 'One');
@ -747,13 +747,13 @@ describe('snabbdom', function () {
patch(vnode0, vnode1);
assert.strictEqual(elm.textContent, 'One');
patch(vnode1, vnode2);
assert.deepStrictEqual(map(prop('textContent'), elm.childNodes), ['Two', 'Three']);
assert.deepEqual(map(prop('textContent'), elm.childNodes), ['Two', 'Three']);
});
it('removes a text node among other elements', function () {
var vnode1 = h('div', ['One', h('span', 'Two')]);
var vnode2 = h('div', [h('div', 'Three')]);
patch(vnode0, vnode1);
assert.deepStrictEqual(map(prop('textContent'), elm.childNodes), ['One', 'Two']);
assert.deepEqual(map(prop('textContent'), elm.childNodes), ['One', 'Two']);
patch(vnode1, vnode2);
assert.strictEqual(elm.childNodes.length, 1);
assert.strictEqual(elm.childNodes[0].tagName, 'DIV');
@ -763,21 +763,21 @@ describe('snabbdom', function () {
var vnode1 = h('div', [h('span', 'One'), h('div', 'Two'), h('b', 'Three')]);
var vnode2 = h('div', [h('b', 'Three'), h('span', 'One'), h('div', 'Two')]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['One', 'Two', 'Three']);
assert.deepEqual(map(inner, elm.children), ['One', 'Two', 'Three']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(prop('tagName'), elm.children), ['B', 'SPAN', 'DIV']);
assert.deepStrictEqual(map(inner, elm.children), ['Three', 'One', 'Two']);
assert.deepEqual(map(prop('tagName'), elm.children), ['B', 'SPAN', 'DIV']);
assert.deepEqual(map(inner, elm.children), ['Three', 'One', 'Two']);
});
it('supports null/undefined children', function () {
var vnode1 = h('i', [null, h('i', '1'), h('i', '2'), null]);
var vnode2 = h('i', [h('i', '2'), undefined, undefined, h('i', '1'), undefined]);
var vnode3 = h('i', [null, h('i', '1'), undefined, null, h('i', '2'), undefined, null]);
elm = patch(vnode0, vnode1).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2']);
assert.deepEqual(map(inner, elm.children), ['1', '2']);
elm = patch(vnode1, vnode2).elm;
assert.deepStrictEqual(map(inner, elm.children), ['2', '1']);
assert.deepEqual(map(inner, elm.children), ['2', '1']);
elm = patch(vnode2, vnode3).elm;
assert.deepStrictEqual(map(inner, elm.children), ['1', '2']);
assert.deepEqual(map(inner, elm.children), ['1', '2']);
});
it('supports all null/undefined children', function () {
var vnode1 = h('i', [h('i', '1'), h('i', '2')]);
@ -787,7 +787,7 @@ describe('snabbdom', function () {
elm = patch(vnode1, vnode2).elm;
assert.strictEqual(elm.children.length, 0);
elm = patch(vnode2, vnode3).elm;
assert.deepStrictEqual(map(inner, elm.children), ['2', '1']);
assert.deepEqual(map(inner, elm.children), ['2', '1']);
});
});
});
@ -1021,7 +1021,7 @@ describe('snabbdom', function () {
]);
var vnode1 = h('div');
patch(vnode0, vnode1);
assert.deepStrictEqual(result, ['pre', 'post']);
assert.deepEqual(result, ['pre', 'post']);
});
it('invokes global `destroy` hook for all removed children', function () {
var result = [];

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import datasetModule from '../modules/dataset'
import { init } from '../snabbdom'

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import { VNode } from '../vnode';
import { init } from '../snabbdom'
@ -38,21 +38,21 @@ describe('event listeners', function () {
elm.click();
elm = patch(vnode1, vnode2).elm;
elm.click();
assert.deepStrictEqual(result, [1, 2]);
assert.deepEqual(result, [1, 2]);
});
it('does calls handler for function in array', function () {
var result: Event[] = [];
function clicked (ev: Event) { result.push(ev); }
var result: number[] = [];
function clicked (n: number) { result.push(n); }
var vnode = h('div', { on: { click: [clicked, 1] as any } }, [
h('a', 'Click my parent'),
]);
elm = patch(vnode0, vnode).elm;
elm.click();
assert.deepStrictEqual(result, [1]);
assert.deepEqual(result, [1]);
});
it('handles changed value in array', function () {
var result: Event[] = [];
function clicked (ev: Event) { result.push(ev); }
var result: number[] = [];
function clicked (n: number) { result.push(n); }
var vnode1 = h('div', { on: { click: [clicked, 1] as any } }, [
h('a', 'Click my parent'),
]);
@ -68,10 +68,10 @@ describe('event listeners', function () {
elm.click();
elm = patch(vnode2, vnode3).elm;
elm.click();
assert.deepStrictEqual(result, [1, 2, 3]);
assert.deepEqual(result, [1, 2, 3]);
});
it('handles changed several values in array', function () {
var result: Event[] = [];
var result: number[][] = [];
function clicked () { result.push([].slice.call(arguments, 0, arguments.length - 2)); }
var vnode1 = h('div', { on: { click: [clicked, 1, 2, 3] as any } }, [
h('a', 'Click my parent'),
@ -88,7 +88,7 @@ describe('event listeners', function () {
elm.click();
elm = patch(vnode2, vnode3).elm;
elm.click();
assert.deepStrictEqual(result, [[1, 2, 3], [1, 2], [2, 3]]);
assert.deepEqual(result, [[1, 2, 3], [1, 2], [2, 3]]);
});
it('detach attached click event handler to element', function () {
var result: Event[] = [];

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import { init } from '../snabbdom'
import h from '../h'

@ -1,4 +1,4 @@
import * as assert from 'assert';
import { assert } from 'chai';
import { jsx } from '../jsx';
describe('snabbdom', function () {

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import { init } from '../snabbdom'
import styleModule from '../modules/style'

@ -1,4 +1,4 @@
import assert from 'assert'
import { assert } from 'chai'
import { init } from '../snabbdom'
import h from '../h'
@ -18,9 +18,9 @@ describe('thunk', function () {
return h('span', 'Number is ' + n);
}
var vnode = thunk('span', 'num', numberInSpan, [22]);
assert.deepStrictEqual(vnode.sel, 'span');
assert.deepStrictEqual(vnode.data.key, 'num');
assert.deepStrictEqual(vnode.data.args, [22]);
assert.deepEqual(vnode.sel, 'span');
assert.deepEqual(vnode.data.key, 'num');
assert.deepEqual(vnode.data.args, [22]);
});
it('calls render function once on data change', function () {
var called = 0;

Loading…
Cancel
Save