DefinitelyTyped/types/superfine/superfine-tests.ts
jameswilddev 7bd3a9ed10
Superfine amendments (#45540)
* Add superfine types.

* Add TSX coverage.

* Add missing "key" property.

* Superfine looks for a SVG element to start creating SVG elements.  This is now enforced through types.

* Fix lint.

* Fix tests using HTML tags in a SVG context.

* Allow empty or single child vnodes.

* Allow strings in JSX.

* Refactor types.

* Lint.
2020-07-07 14:04:25 -07:00

227 lines
6.6 KiB
TypeScript

import * as superfine from 'superfine';
// Strongly typed HTML element root.
superfine.patch(
document.createElement('div'),
superfine.h(
'div',
{
onclick: e => {
console.log(e.clientX);
},
},
[
superfine.h(
'input',
{
type: 'number',
value: '3',
min: '2',
max: '5',
disabled: false,
onchange: e => {
// TypeScript DOM library limitations prevent typing of e.target.value.
console.log(e.target);
}
},
[]
),
superfine.h(
'svg',
{
onclick: e => {
console.log(e.clientX);
},
},
[
superfine.h(
'g',
{},
superfine.h(
'rect',
{
},
[]
),
),
superfine.h(
'g',
{},
[
superfine.h(
'rect',
{
},
[]
),
superfine.h(
'rect',
{
}
),
superfine.h(
'text',
{
},
'example string'
),
superfine.h(
'text',
{
},
['example string']
),
'example string',
superfine.h(
'rect',
{
key: 'example key a'
},
[]
),
superfine.h(
'rect',
{
key: 'example key b'
},
[]
)
]
)
]
),
superfine.h(
'a',
{
href: '#anything'
},
[
superfine.h(
'ul',
{},
superfine.h(
'li',
{
},
[]
)
),
superfine.h(
'ul',
{},
[
superfine.h(
'li',
{
},
[]
),
superfine.h(
'li',
{
}
),
superfine.h(
'li',
{
},
'example string'
),
superfine.h(
'li',
{
},
['example string']
),
'example string',
superfine.h(
'li',
{
key: 'example key a'
},
[]
),
superfine.h(
'li',
{
key: 'example key b'
},
[]
)
]
)
]
)
]
)
);
// Strongly typed SVG element root.
superfine.patch(
document.createElementNS('http://www.w3.org/2000/svg', 'svg'),
superfine.h(
'svg',
{
onclick: e => {
console.log(e.clientX);
},
},
[
superfine.h(
'g',
{},
superfine.h(
'rect',
{
},
[]
),
),
superfine.h(
'g',
{},
[
superfine.h(
'rect',
{
},
[]
),
superfine.h(
'rect',
{
}
),
superfine.h(
'text',
{
},
'example string'
),
superfine.h(
'text',
{
},
['example string']
),
'example string',
superfine.h(
'rect',
{
key: 'example key a'
},
[]
),
superfine.h(
'rect',
{
key: 'example key b'
},
[]
)
]
)
]
)
);