test: compare deep instead of JSON in assertions (#531)

pull/502/head
Shahar Dawn Or 5 years ago committed by GitHub
parent 693872cf73
commit d524860ad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,34 +6,57 @@ describe('snabbdom', function () {
it('can be used as a jsxFactory method', function () { it('can be used as a jsxFactory method', function () {
const vnode = <div title="Hello World">Hello World</div>; const vnode = <div title="Hello World">Hello World</div>;
assert.strictEqual(JSON.stringify(vnode), JSON.stringify({ assert.deepStrictEqual(vnode, {
sel: 'div', sel: 'div',
data: { title: 'Hello World' }, data: { title: 'Hello World' },
children: undefined,
elm: undefined,
text: 'Hello World', text: 'Hello World',
})); key: undefined
});
}); });
it('creates text property for text only child', function () { it('creates text property for text only child', function () {
const vnode = <div>foo bar</div>; const vnode = <div>foo bar</div>;
assert.strictEqual(JSON.stringify(vnode), JSON.stringify({ assert.deepStrictEqual(vnode, {
sel: 'div', sel: 'div',
data: {}, data: {},
children: undefined,
elm: undefined,
text: 'foo bar', text: 'foo bar',
})); key: undefined
});
}); });
it('creates an array of children for multiple children', function () { it('creates an array of children for multiple children', function () {
const vnode = <div>{'foo'}{'bar'}</div>; const vnode = <div>{'foo'}{'bar'}</div>;
assert.strictEqual(JSON.stringify(vnode), JSON.stringify({ assert.deepStrictEqual(vnode, {
sel: 'div', sel: 'div',
data: {}, data: {},
children: [ children: [
{ text: 'foo' }, {
{ text: 'bar' }, sel: undefined,
] data: undefined,
})); children: undefined,
elm: undefined,
text: 'foo',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: 'bar',
key: undefined
},
],
elm: undefined,
text: undefined,
key: undefined
});
}); });
it('flattens children', function () { it('flattens children', function () {
@ -45,16 +68,47 @@ describe('snabbdom', function () {
</section> </section>
); );
assert.strictEqual(JSON.stringify(vnode), JSON.stringify({ assert.deepStrictEqual(vnode, {
sel: 'section', sel: 'section',
data: {}, data: {},
children: [ children: [
{ sel: 'h1', data: {}, text: 'A Heading' }, {
{ text: 'some description' }, sel: 'h1',
{ sel: 'span', data: {}, text: 'part1' }, data: {},
{ sel: 'span', data: {}, text: 'part2' }, children: undefined,
elm: undefined,
text: 'A Heading',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: 'some description',
key: undefined
},
{
sel: 'span',
data: {},
children: undefined,
elm: undefined,
text: 'part1',
key: undefined
},
{
sel: 'span',
data: {},
children: undefined,
elm: undefined,
text: 'part2',
key: undefined
},
], ],
})); elm: undefined,
text: undefined,
key: undefined
});
}); });
it('removes falsey children', function () { it('removes falsey children', function () {
@ -76,17 +130,55 @@ describe('snabbdom', function () {
</div> </div>
); );
assert.strictEqual(JSON.stringify(vnode), JSON.stringify({ assert.deepStrictEqual(vnode, {
sel: 'div', sel: 'div',
data: {}, data: {},
children: [ children: [
{ text: 'Login Form' }, {
{ text: 'Login Attempts: ' }, sel: undefined,
{ text: '0' }, data: undefined,
{ text: 'Logged In: ' }, children: undefined,
{ text: 'true' }, elm: undefined,
text: 'Login Form',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: 'Login Attempts: ',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: '0',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: 'Logged In: ',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: 'true',
key: undefined
},
], ],
})); elm: undefined,
text: undefined,
key: undefined
});
}); });
it('works with a function component', function () { it('works with a function component', function () {
@ -100,19 +192,71 @@ describe('snabbdom', function () {
</div> </div>
); );
assert.strictEqual(JSON.stringify(vnode), JSON.stringify({ assert.deepStrictEqual(vnode, {
sel: 'div', sel: 'div',
data: {}, data: {},
children: [ children: [
{ sel: 'a', data: { attrs: { href: 'https://github.com/snabbdom/snabbdom' } }, text: 'Snabbdom' }, {
{ text: 'and tsx' }, sel: 'a',
{ sel: 'span', data: {}, text: 'work' }, data: { attrs: { href: 'https://github.com/snabbdom/snabbdom' } },
{ sel: 'span', data: {}, text: 'like' }, children: undefined,
{ sel: 'span', data: {}, text: 'a' }, elm: undefined,
{ sel: 'span', data: {}, text: 'charm!' }, text: 'Snabbdom',
{ text: '💃🕺🎉' }, key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: 'and tsx',
key: undefined
},
{
sel: 'span',
data: {},
children: undefined,
elm: undefined,
text: 'work',
key: undefined
},
{
sel: 'span',
data: {},
children: undefined,
elm: undefined,
text: 'like',
key: undefined
},
{
sel: 'span',
data: {},
children: undefined,
elm: undefined,
text: 'a',
key: undefined
},
{
sel: 'span',
data: {},
children: undefined,
elm: undefined,
text: 'charm!',
key: undefined
},
{
sel: undefined,
data: undefined,
children: undefined,
elm: undefined,
text: '💃🕺🎉',
key: undefined
},
], ],
})); elm: undefined,
text: undefined,
key: undefined
});
}) })
}); });
}); });

Loading…
Cancel
Save