//TODO: Test that portals are suspendable
/* IMPORT */
import * as Voby from 'voby';
import {Dynamic, ErrorBoundary, For, If, KeepAlive, Portal, Suspense, Switch, Ternary} from 'voby';
import {useContext, useEffect, useInterval, useMemo, usePromise, useResource, useTimeout} from 'voby';
import {$, $$, createContext, createDirective, createElement, h, hmr, html, lazy, render, renderToString, store, template, untrack} from 'voby';
import type {Observable, ObservableReadonly} from 'voby';
globalThis.Voby = Voby;
/* TYPE */
type Constructor = new ( ...args: Args ) => T;
type FunctionUnwrap = T extends ({ (): infer U }) ? U : T;
/* HELPERS */
const TEST_INTERVAL = 500; // Lowering this makes it easier to spot some memory leaks
const assert = ( result: boolean, message?: string ): void => {
console.assert ( result, message );
};
const random = (): number => { // It's important for testing that 0, 1 or reused numbers are never returned
const value = Math.random ();
if ( value === 0 || value === 1 ) return random ();
return value;
};
const randomBigInt = (): bigint => {
return BigInt ( Math.floor ( random () * 10000 ) );
};
const randomColor = (): string => {
return `#${Math.floor ( random () * 0xFFFFFF ).toString ( 16 ).padStart ( 6, '0' )}`;
};
const TestSnapshots = ({ Component, props }: { Component: ( JSX.Component | Constructor ) & { test: { error?: string, static?: boolean, wrap?: boolean, snapshots?: string[] } }, props?: Record }): JSX.Element => {
const ref = $();
let index = -1;
let htmlPrev = '';
let ticks = 0;
let done = false;
const getHTML = (): string => {
const element = ref ();
if ( !element ) return '';
return element.innerHTML;
};
const getSnapshot = ( html: string ): string => {
const htmlWithoutTitle = html.replace ( /[a-zA-Z0-9 -]*<\/h3>/, '' );
const htmlWithRandom = htmlWithoutTitle.replace ( /0\.\d+/g, '{random}' );
const htmlWitRandomBigint = htmlWithRandom.replace ( /(? {
if ( done ) return;
const indexPrev = index;
ticks += 1;
index = ( index + 1 ) % Component.test.snapshots?.length;
if ( index < indexPrev && Component.test.wrap === false ) {
done = true;
return;
}
const expectedSnapshot = Component.test.snapshots?.[index];
const actualHTML = getHTML ();
const actualSnapshot = getSnapshot ( actualHTML );
assert ( actualSnapshot === expectedSnapshot, `[${Component.name}]: Expected '${actualSnapshot}' to be equal to '${expectedSnapshot}'` );
if ( expectedSnapshot.includes ( '{random}' ) ) {
assert ( actualHTML !== htmlPrev, `[${Component.name}]: Expected to find different {random} values in the HTML` );
}
if ( expectedSnapshot.includes ( '{random-bigint}' ) ) {
assert ( actualHTML !== htmlPrev, `[${Component.name}]: Expected to find different {random-bigint} values in the HTML` );
}
if ( expectedSnapshot.includes ( '{random-color}' ) ) {
assert ( actualHTML !== htmlPrev, `[${Component.name}]: Expected to find different {random-color} values in the HTML` );
}
htmlPrev = actualHTML;
};
const noUpdate = (): void => {
assert ( false, `[${Component.name}]: Expected no updates to ever happen` );
};
const yesUpdate = (): void => {
if ( Component.test.static ) return;
if ( ticks > 1 ) return;
assert ( false, `[${Component.name}]: Expected at least one update` );
};
if ( Component.test.error ) {
try {
$$($$($$( )));
assert ( false, `[${Component.name}]: Expected it to throw an error` );
} catch ( error ) {
assert ( error instanceof Error, `[${Component.name}]: Expected it to throw an error` );
assert ( error.message === Component.test.error, `[${Component.name}]: Expected error message "${error.message}" to be equal to "${Component.test.error}"` );
}
} else {
useEffect ( () => {
const root = ref ();
if ( !root ) return;
tick ();
const timeoutId = setTimeout ( yesUpdate, 1500 );
const onMutation = Component.test.static ? noUpdate : tick;
const observer = new MutationObserver ( onMutation );
const options = { attributes: true, childList: true, characterData: true, subtree: true };
observer.observe ( root, options );
return () => observer.disconnect ();
});
return (
);
}
};
/* MAIN */
//TODO: Test that error boundaries wrapped around built-in components work
//TODO: Test template with all sorts of supported props
//TODO: Automate all tests
//TODO: Enable all tests
const TestNullStatic = (): JSX.Element => {
return (
<>
Null - Static
{null}
>
);
};
TestNullStatic.test = {
static: true,
snapshots: [
'
'
]
};
const TestNullObservable = (): JSX.Element => {
const o = $( null );
const toggle = () => o ( prev => ( prev === null ) ? '' : null );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Null - Observable
{o}
>
);
};
TestNullObservable.test = {
static: false,
snapshots: [
'
',
'
'
]
};
const TestNullFunction = (): JSX.Element => {
const o = $( null );
const toggle = () => o ( prev => ( prev === null ) ? '' : null );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Null - Function
{() => o ()}
>
);
};
TestNullFunction.test = {
static: false,
snapshots: [
'
',
'
'
]
};
const TestNullRemoval = (): JSX.Element => {
const o = $( null );
const toggle = () => o ( prev => ( prev === null ) ? '' : null );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Null - Removal
({o})
>
);
};
TestNullRemoval.test = {
static: false,
snapshots: [
'()
',
'()
'
]
};
const TestUndefinedStatic = (): JSX.Element => {
return (
<>
Undefined - Static
{undefined}
>
);
};
TestUndefinedStatic.test = {
static: true,
snapshots: [
'
'
]
};
const TestUndefinedObservable = (): JSX.Element => {
const o = $( undefined );
const toggle = () => o ( prev => ( prev === undefined ) ? '' : undefined );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Undefined - Observable
{o}
>
);
};
TestUndefinedObservable.test = {
static: false,
snapshots: [
'
',
'
'
]
};
const TestUndefinedFunction = (): JSX.Element => {
const o = $( undefined );
const toggle = () => o ( prev => ( prev === undefined ) ? '' : undefined );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Undefined - Function
{() => o ()}
>
);
};
TestUndefinedFunction.test = {
static: false,
snapshots: [
'
',
'
'
]
};
const TestUndefinedRemoval = (): JSX.Element => {
const o = $( undefined );
const toggle = () => o ( prev => ( prev === undefined ) ? '' : undefined );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Undefined - Removal
({o})
>
);
};
TestUndefinedRemoval.test = {
static: false,
snapshots: [
'()
',
'()
'
]
};
const TestBooleanStatic = (): JSX.Element => {
return (
<>
Boolean - Static
{true}{false}
>
);
};
TestBooleanStatic.test = {
static: true,
snapshots: [
'
'
]
};
const TestBooleanObservable = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Boolean - Observable
{o}
>
);
};
TestBooleanObservable.test = {
static: true,
snapshots: [
'
'
]
};
const TestBooleanFunction = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Boolean - Function
{() => o ()}
>
);
};
TestBooleanFunction.test = {
static: true,
snapshots: [
'
'
]
};
const TestBooleanRemoval = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => prev ? null : true );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Boolean - Removal
({o})
>
);
};
TestBooleanRemoval.test = {
static: true,
snapshots: [
'()
'
]
};
const TestSymbolStatic = (): JSX.Element => {
return (
<>
Symbol - Static
{Symbol ()}
>
);
};
TestSymbolStatic.test = {
static: true,
snapshots: [
'
'
]
};
const TestSymbolObservable = (): JSX.Element => {
const o = $( Symbol () );
const randomize = () => o ( Symbol () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Symbol - Observable
{o}
>
);
};
TestSymbolObservable.test = {
static: true,
snapshots: [
'
'
]
};
const TestSymbolFunction = (): JSX.Element => {
const o = $( Symbol () );
const randomize = () => o ( Symbol () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Symbol - Function
{() => o ()}
>
);
};
TestSymbolFunction.test = {
static: true,
snapshots: [
'
'
]
};
const TestSymbolRemoval = (): JSX.Element => {
const o = $( Symbol () );
const randomize = () => o ( prev => prev ? null : Symbol () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Symbol - Removal
({o})
>
);
};
TestSymbolRemoval.test = {
static: true,
snapshots: [
'()
'
]
};
const TestNumberStatic = (): JSX.Element => {
return (
<>
Number - Static
{123}
>
);
};
TestNumberStatic.test = {
static: true,
snapshots: [
'123
'
]
};
const TestNumberObservable = (): JSX.Element => {
const o = $( random () );
const randomize = () => o ( random () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Number - Observable
{o}
>
);
};
TestNumberObservable.test = {
static: false,
snapshots: [
'{random}
'
]
};
const TestNumberFunction = (): JSX.Element => {
const o = $( random () );
const randomize = () => o ( random () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Number - Function
{() => o ()}
>
);
};
TestNumberFunction.test = {
static: false,
snapshots: [
'{random}
'
]
};
const TestNumberRemoval = (): JSX.Element => {
const o = $( random () );
const randomize = () => o ( prev => prev ? null : random () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Number - Removal
({o})
>
);
};
TestNumberRemoval.test = {
static: false,
snapshots: [
'({random})
',
'()
'
]
};
const TestBigIntStatic = (): JSX.Element => {
return (
<>
BigInt - Static
{123123n}n
>
);
};
TestBigIntStatic.test = {
static: true,
snapshots: [
'123123n
'
]
};
const TestBigIntObservable = (): JSX.Element => {
const o = $( randomBigInt () );
const randomize = () => o ( randomBigInt () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
BigInt - Observable
{o}n
>
);
};
TestBigIntObservable.test = {
static: false,
snapshots: [
'{random-bigint}n
'
]
};
const TestBigIntFunction = (): JSX.Element => {
const o = $( randomBigInt () );
const randomize = () => o ( randomBigInt () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
BigInt - Function
{() => o ()}n
>
);
};
TestBigIntFunction.test = {
static: false,
snapshots: [
'{random-bigint}n
'
]
};
const TestBigIntRemoval = (): JSX.Element => {
const o = $( randomBigInt () );
const randomize = () => o ( prev => prev ? null : randomBigInt () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
BigInt - Removal
({o}n)
>
);
};
TestBigIntRemoval.test = {
static: false,
snapshots: [
'({random-bigint}n)
',
'(n)
'
]
};
const TestStringStatic = (): JSX.Element => {
return (
<>
String - Static
{'string'}
>
);
};
TestStringStatic.test = {
static: true,
snapshots: [
'string
'
]
};
const TestStringObservable = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
String - Observable
{o}
>
);
};
TestStringObservable.test = {
static: false,
snapshots: [
'{random}
'
]
};
const TestStringObservableStatic = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
String - Observable Static
{o ()}
>
);
};
TestStringObservableStatic.test = {
static: true,
snapshots: [
'{random}
'
]
};
const TestStringObservableDeepStatic = (): JSX.Element => {
return useMemo ( () => {
const Deep = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
String - Observable Deep Static
{o ()}
>
);
};
return ;
});
};
TestStringObservableDeepStatic.test = {
static: true,
snapshots: [
'{random}
'
]
};
const TestStringFunction = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
String - Function
{() => o ()}
>
);
};
TestStringFunction.test = {
static: false,
snapshots: [
'{random}
'
]
};
const TestStringRemoval = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( prev => prev ? null : String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
String - Removal
({o})
>
);
};
TestStringRemoval.test = {
static: false,
snapshots: [
'({random})
',
'()
'
]
};
const TestAttributeStatic = (): JSX.Element => {
return (
<>
Attribute - Static
content
>
);
};
TestAttributeStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestAttributeObservable = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Attribute - Observable
content
>
);
};
TestAttributeObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestAttributeObservableBoolean = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Attribute - Observable Boolean
content
>
);
};
TestAttributeObservableBoolean.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestAttributeFunction = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Attribute - Function
`dark${o ()}`}>content
>
);
};
TestAttributeFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestAttributeFunctionBoolean = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Attribute - Function Boolean
!o ()}>content
>
);
};
TestAttributeFunctionBoolean.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestAttributeRemoval = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? null : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Attribute - Removal
content
>
);
};
TestAttributeRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestAttributeBooleanStatic = (): JSX.Element => {
return (
<>
Attribute Boolan - Static
content
content
>
);
};
TestAttributeBooleanStatic.test = {
static: true,
snapshots: [
'content
content
'
]
};
const TestPropertyCheckedStatic = (): JSX.Element => {
return (
<>
Property - Checked Static
>
);
};
const TestPropertyCheckedObservable = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Property - Checked Observable
>
);
};
const TestPropertyCheckedFunction = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Property - Checked Function
o ()} />
>
);
};
const TestPropertyCheckedRemoval = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => prev ? null : true );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Property - Checked Removal
>
);
};
const TestPropertyValueStatic = (): JSX.Element => {
return (
<>
Property - Value Static
>
);
};
const TestPropertyValueObservable = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Property - Value Observable
>
);
};
const TestPropertyValueFunction = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Property - Value Function
o ()} />
>
);
};
const TestPropertyValueRemoval = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( prev => prev ? null : String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Property - Value Removal
>
);
};
const TestInputLabelFor = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( prev => prev ? null : String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Input - Label For
htmlFor
for
>
);
};
const TestInputForm = (): JSX.Element => {
return (
<>
Input - Input Form
>
);
};
TestInputForm.test = {
static: true,
snapshots: [
' '
]
};
const TestCheckboxIndeterminateToggle = (): JSX.Element => {
const o = $( false );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Checkbox - Indeterminate Toggle
>
);
};
TestCheckboxIndeterminateToggle.test = {
static: true,
snapshots: [
' '
]
};
const TestProgressIndeterminateToggle = (): JSX.Element => {
const o = $( .25 );
const values = [.25, null, .5, undefined];
const cycle = () => o ( prev => values[( values.indexOf ( prev ) + 1 ) % values.length] );
useInterval ( cycle, TEST_INTERVAL );
return (
<>
Progress - Indeterminate Toggle
>
);
};
TestProgressIndeterminateToggle.test = {
static: false,
snapshots: [
' ',
' ',
' ',
' '
]
};
const TestSelectStaticOption = (): JSX.Element => {
const ref = $();
const assert = () => console.assert ( ref ()?.value === 'bar' );
setTimeout ( assert, 1 );
return (
<>
Select - Static Option
foo
bar
baz
qux
>
);
};
TestSelectStaticOption.test = {
static: true,
snapshots: [
'foo bar baz qux '
]
};
const TestSelectStaticValue = (): JSX.Element => {
const ref = $();
const assert = () => console.assert ( ref ()?.value === 'bar' );
setTimeout ( assert, 1 );
return (
<>
Select - Static Value
foo
bar
baz
qux
>
);
};
TestSelectStaticValue.test = {
static: true,
snapshots: [
'foo bar baz qux '
]
};
const TestSelectObservableOption = (): JSX.Element => {
const ref = $();
const branch = $(true);
const assert = () => console.assert ( ref ()?.value === ( branch () ? 'bar' : 'qux' ) );
const toggle = () => branch ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
useInterval ( assert, TEST_INTERVAL );
setTimeout ( assert, 1 );
return (
<>
Select - Observable Option
foo
bar
baz
!branch ()}>qux
>
);
};
TestSelectObservableOption.test = {
static: true,
snapshots: [
'foo bar baz qux '
]
};
const TestSelectObservableValue = (): JSX.Element => {
const ref = $();
const value = $('bar');
const assert = () => console.assert ( ref ()?.value === value () );
const toggle = () => value ( prev => prev === 'bar' ? 'qux' : 'bar' );
useInterval ( toggle, TEST_INTERVAL );
useInterval ( assert, TEST_INTERVAL );
setTimeout ( assert, 1 );
return (
<>
Select - Observable Value
foo
bar
baz
qux
>
);
};
TestSelectObservableValue.test = {
static: true,
snapshots: [
'foo bar baz qux '
]
};
const TestIdStatic = (): JSX.Element => {
return (
<>
ID - Static
content
>
);
};
TestIdStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestIdObservable = (): JSX.Element => {
const o = $( 'foo' );
const toggle = () => o ( prev => ( prev === 'foo' ) ? 'bar' : 'foo' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
ID - Observable
content
>
);
};
TestIdObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestIdFunction = (): JSX.Element => {
const o = $( 'foo' );
const toggle = () => o ( prev => ( prev === 'foo' ) ? 'bar' : 'foo' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
ID - Function
o ()}>content
>
);
};
TestIdFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestIdRemoval = (): JSX.Element => {
const o = $( 'foo' );
const toggle = () => o ( prev => prev ? null : 'foo' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
ID - Removal
content
>
);
};
TestIdRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassNameStatic = (): JSX.Element => {
return (
<>
ClassName - Static
content
>
);
};
TestClassNameStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassNameObservable = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
ClassName - Observable
content
>
);
};
TestClassNameObservable.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassNameFunction = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
ClassName - Function
o ()}>content
>
);
};
TestClassNameFunction.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassStatic = (): JSX.Element => {
return (
<>
Class - Static
content
>
);
};
TestClassStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassStaticString = (): JSX.Element => {
return (
<>
Class - Static String
content
>
);
};
TestClassStaticString.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassObservable = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Class - Observable
content
>
);
};
TestClassObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassObservableString = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Class - Observable String
content
>
);
};
TestClassObservableString.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassFunction = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Class - Function Boolean
o () }}>content
>
);
};
TestClassFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassFunctionString = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Class - Function String
o ()}>content
>
);
};
TestClassFunctionString.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassRemoval = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => prev ? null : true );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Class - Removal
content
>
);
};
TestClassRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassRemovalString = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => prev ? null : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Class - Removal String
content
>
);
};
TestClassRemovalString.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayStatic = (): JSX.Element => {
return (
<>
Classes - Array Static
content
>
);
};
TestClassesArrayStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassesArrayStaticMultiple = (): JSX.Element => {
return (
<>
Classes - Array Static Multiple
content
>
);
};
TestClassesArrayStaticMultiple.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassesArrayObservable = (): JSX.Element => {
const o = $([ 'red', false ]);
const toggle = () => o ( prev => prev[0] ? [false, 'blue'] : ['red', false] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Observable
content
>
);
};
TestClassesArrayObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayObservableMultiple = (): JSX.Element => {
const o = $([ 'red bold', false ]);
const toggle = () => o ( prev => prev[0] ? [false, 'blue'] : ['red bold', false] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Observable Multiple
content
>
);
};
TestClassesArrayObservableMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayObservableValue = (): JSX.Element => {
const o = $('red');
const toggle = () => o ( prev => prev === 'red' ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Observable Value
content
>
);
};
TestClassesArrayObservableValue.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayFunction = (): JSX.Element => {
const o = $([ 'red', false ]);
const toggle = () => o ( prev => prev[0] ? [false, 'blue'] : ['red', false] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Function
o ()}>content
>
);
};
TestClassesArrayFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayFunctionMultiple = (): JSX.Element => {
const o = $([ 'red bold', false ]);
const toggle = () => o ( prev => prev[0] ? [false, 'blue'] : ['red bold', false] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Function Multiple
o ()}>content
>
);
};
TestClassesArrayFunctionMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayFunctionValue = (): JSX.Element => {
const o = $('red');
const toggle = () => o ( prev => prev === 'red' ? 'blue' : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Function Value
o ()]}>content
>
);
};
TestClassesArrayFunctionValue.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayStore = (): JSX.Element => {
const o = store ([ 'red', false ]);
const toggle = () => {
if ( o[0] ) {
o[0] = false;
o[1] = 'blue';
} else {
o[0] = 'red';
o[1] = false;
}
};
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Store
content
>
);
};
TestClassesArrayStore.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayStoreMultiple = (): JSX.Element => {
const o = store ([ 'red bold', false ]);
const toggle = () => {
if ( o[0] ) {
o[0] = false;
o[1] = 'blue';
} else {
o[0] = 'red bold';
o[1] = false;
}
};
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Store Multiple
content
>
);
};
TestClassesArrayStoreMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayNestedStatic = (): JSX.Element => {
const o = $(['red', ['bold', { 'italic': true }]]);
return (
<>
Classes - Array Nested Static
content
>
);
};
TestClassesArrayNestedStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassesArrayRemoval = (): JSX.Element => {
const o = $ | null>([ 'red', false ]);
const toggle = () => o ( prev => prev ? null : ['red', false] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Removal
content
>
);
};
TestClassesArrayRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayRemovalMultiple = (): JSX.Element => {
const o = $ | null>([ 'red bold', false ]);
const toggle = () => o ( prev => prev ? null : ['red bold', false] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Removal Multiple
content
>
);
};
TestClassesArrayRemovalMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesArrayCleanup = (): JSX.Element => {
const o = $([ 'red' ]);
const toggle = () => o ( prev => prev[0] === 'red' ? ['blue'] : ['red'] );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Array Cleanup
content
>
);
};
TestClassesArrayCleanup.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectStatic = (): JSX.Element => {
return (
<>
Classes - Object Static
content
>
);
};
TestClassesObjectStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassesObjectStaticMultiple = (): JSX.Element => {
return (
<>
Classes - Object Static Multiple
content
>
);
};
TestClassesObjectStaticMultiple.test = {
static: true,
snapshots: [
'content
'
]
};
const TestClassesObjectObservable = (): JSX.Element => {
const o = $({ red: true, blue: false });
const toggle = () => o ( prev => prev.red ? { red: false, blue: true } : { red: true, blue: false } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Observable
content
>
);
};
TestClassesObjectObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectObservableMultiple = (): JSX.Element => {
const o = $({ 'red bold': true, blue: false });
const toggle = () => o ( prev => prev['red bold'] ? { 'red bold': false, blue: true } : { 'red bold': true, blue: false } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Observable Multiple
content
>
);
};
TestClassesObjectObservableMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectFunction = (): JSX.Element => {
const o = $({ red: true, blue: false });
const toggle = () => o ( prev => prev.red ? { red: false, blue: true } : { red: true, blue: false } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Function
o ()}>content
>
);
};
TestClassesObjectFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectFunctionMultiple = (): JSX.Element => {
const o = $({ 'red bold': true, blue: false });
const toggle = () => o ( prev => prev['red bold'] ? { 'red bold': false, blue: true } : { 'red bold': true, blue: false } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Function Multiple
o ()}>content
>
);
};
TestClassesObjectFunctionMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectStore = (): JSX.Element => {
const o = store ({ red: true, blue: false });
const toggle = () => {
if ( o.red ) {
o.red = false;
o.blue = true;
} else {
o.red = true;
o.blue = false;
}
};
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Store
content
>
);
};
TestClassesObjectStore.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectStoreMultiple = (): JSX.Element => {
const o = store ({ 'red bold': true, blue: false });
const toggle = () => {
if ( o['red bold'] ) {
o['red bold'] = false;
o.blue = true;
} else {
o['red bold'] = true;
o.blue = false;
}
};
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Store Multiple
content
>
);
};
TestClassesObjectStoreMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectRemoval = (): JSX.Element => {
const o = $ | null>({ red: true, blue: false });
const toggle = () => o ( prev => prev ? null : { red: true, blue: false } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Removal
content
>
);
};
TestClassesObjectRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectRemovalMultiple = (): JSX.Element => {
const o = $ | null>({ 'red bold': true, blue: false });
const toggle = () => o ( prev => prev ? null : { 'red bold': true, blue: false } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Removal Multiple
content
>
);
};
TestClassesObjectRemovalMultiple.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestClassesObjectCleanup = (): JSX.Element => {
const o = $({ red: true });
const toggle = () => o ( prev => prev.red ? { blue: true } : { red: true } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Classes - Object Cleanup
content
>
);
};
TestClassesObjectCleanup.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleStatic = (): JSX.Element => {
return (
<>
Style - Static
content
>
);
};
TestStyleStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestStyleStaticNumeric = (): JSX.Element => {
return (
<>
Style - Static Numeric
content
>
);
};
TestStyleStaticNumeric.test = {
static: true,
snapshots: [
'content
'
]
};
const TestStyleStaticString = (): JSX.Element => {
return (
<>
Style - Static String
content
>
);
};
TestStyleStaticString.test = {
static: true,
snapshots: [
'content
'
]
};
const TestStyleStaticVariable = (): JSX.Element => {
return (
<>
Style - Static Variable
content
>
);
};
TestStyleStaticVariable.test = {
static: true,
snapshots: [
'content
'
]
};
const TestStyleObservable = (): JSX.Element => {
const o = $( 'green' );
const toggle = () => o ( prev => ( prev === 'green' ) ? 'orange' : 'green' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Observable
content
>
);
};
TestStyleObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleObservableNumeric = (): JSX.Element => {
const o = $( { flexGrow: 1, width: 50 } );
const toggle = () => o ( prev => ( prev.flexGrow === 1 ) ? { flexGrow: 2, width: 100 } : { flexGrow: 1, width: 50 } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Observable Numeric
content
>
);
};
TestStyleObservableNumeric.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleObservableString = (): JSX.Element => {
const o = $( 'color: green' );
const toggle = () => o ( prev => ( prev === 'color: green' ) ? 'color: orange' : 'color: green' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Observable String
content
>
);
};
TestStyleObservableString.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleObservableVariable = (): JSX.Element => {
const o = $( 'green' );
const toggle = () => o ( prev => ( prev === 'orange' ) ? 'green' : 'orange' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Observable Variable
content
>
);
};
TestStyleObservableVariable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleFunction = (): JSX.Element => {
const o = $( 'green' );
const toggle = () => o ( prev => ( prev === 'green' ) ? 'orange' : 'green' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Function
o () }}>content
>
);
};
TestStyleFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleFunctionNumeric = (): JSX.Element => {
const o = $( { flexGrow: 1, width: 50 } );
const toggle = () => o ( prev => ( prev.flexGrow === 1 ) ? { flexGrow: 2, width: 100 } : { flexGrow: 1, width: 50 } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Function Numeric
o ()}>content
>
);
};
TestStyleFunctionNumeric.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleFunctionString = (): JSX.Element => {
const o = $( 'color: green' );
const toggle = () => o ( prev => ( prev === 'color: green' ) ? 'color: orange' : 'color: green' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Function String
o ()}>content
>
);
};
TestStyleFunctionString.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleFunctionVariable = (): JSX.Element => {
const o = $( 'green' );
const toggle = () => o ( prev => ( prev === 'orange' ) ? 'green' : 'orange' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Function Variable
o () }}>content
>
);
};
TestStyleFunctionVariable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStyleRemoval = (): JSX.Element => {
const o = $( 'green' );
const toggle = () => o ( prev => prev ? null : 'green' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Style - Removal
content
>
);
};
TestStyleRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStylesStatic = (): JSX.Element => {
return (
<>
Styles - Static
content
>
);
};
TestStylesStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestStylesObservable = (): JSX.Element => {
const o = $({ color: 'orange', fontWeight: 'normal' });
const toggle = () => o ( prev => ( prev.color === 'orange' ) ? { color: 'green', fontWeight: 'bold' } : { color: 'orange', fontWeight: 'normal' } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Styles - Observable
content
>
);
};
TestStylesObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStylesFunction = (): JSX.Element => {
const o = $({ color: 'orange', fontWeight: 'normal' });
const toggle = () => o ( prev => ( prev.color === 'orange' ) ? { color: 'green', fontWeight: 'bold' } : { color: 'orange', fontWeight: 'normal' } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Styles - Function
o ()}>content
>
);
};
TestStylesFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStylesStore = (): JSX.Element => {
const o = store ({ color: 'orange', fontWeight: 'normal' });
const toggle = () => {
if ( o.color === 'orange' ) {
o.color = 'green';
o.fontWeight = 'bold';
} else {
o.color = 'orange';
o.fontWeight = 'normal';
}
};
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Styles - Store
content
>
);
};
TestStylesStore.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStylesRemoval = (): JSX.Element => {
const o = $ | null>({ color: 'orange', fontWeight: 'normal' });
const toggle = () => o ( prev => prev ? null : { color: 'orange', fontWeight: 'normal' } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Styles - Removal
content
>
);
};
TestStylesRemoval.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStylesCleanup = (): JSX.Element => {
const o = $({ color: 'orange', fontWeight: 'bold' });
const toggle = () => o ( prev => ( prev.color === 'orange' ) ? { fontStyle: 'italic', textDecoration: 'line-through' } : { color: 'orange', fontWeight: 'bold' } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Styles - Observable Cleanup
content
>
);
};
TestStylesCleanup.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestStylesMixed = (): JSX.Element => {
return (
<>
Styles - Mixed
'italic' }]]}>example
>
)
};
TestStylesMixed.test = {
static: true,
snapshots: [
'example
'
]
};
const TestHTMLFunctionStatic = (): JSX.Element => {
return (
<>
HTML - Function - Static
{html`
<${If} when=${true}>
${random ()}
${If}>
`}
>
);
};
TestHTMLFunctionStatic.test = {
static: true,
snapshots: [
'{random}
'
]
};
const TestHTMLFunctionStaticRegistry = (): JSX.Element => {
const P = (): JSX.Element => {
return {random ()}
;
};
html.register ({ If, P });
return (
<>
HTML - Function - Static Registry
{html`
`}
>
);
};
TestHTMLFunctionStaticRegistry.test = {
static: true,
snapshots: [
'{random}
'
]
};
const TestHTMLInnerHTMLStatic = (): JSX.Element => {
return (
<>
HTML - innerHTML - Static
>
);
};
TestHTMLInnerHTMLStatic.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLInnerHTMLObservable = (): JSX.Element => {
const o = $( 'danger1 ' );
const toggle = () => o ( prev => ( prev === 'danger1 ' ) ? 'danger2 ' : 'danger1 ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - innerHTML - Observable
>
);
};
TestHTMLInnerHTMLObservable.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLInnerHTMLFunction = (): JSX.Element => {
const o = $( 'danger1 ' );
const toggle = () => o ( prev => ( prev === 'danger1 ' ) ? 'danger2 ' : 'danger1 ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - innerHTML - Function
o ()} />
>
);
};
TestHTMLInnerHTMLFunction.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLOuterHTMLStatic = (): JSX.Element => {
return (
<>
HTML - outerHTML - Static
>
);
};
TestHTMLOuterHTMLStatic.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLOuterHTMLObservable = (): JSX.Element => {
const o = $( 'danger1 ' );
const toggle = () => o ( prev => ( prev === 'danger1 ' ) ? 'danger2 ' : 'danger1 ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - outerHTML - Observable
>
);
};
TestHTMLOuterHTMLObservable.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLOuterHTMLFunction = (): JSX.Element => {
const o = $( 'danger1 ' );
const toggle = () => o ( prev => ( prev === 'danger1 ' ) ? 'danger2 ' : 'danger1 ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - outerHTML - Function
o ()} />
>
);
};
TestHTMLOuterHTMLFunction.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLTextContentStatic = (): JSX.Element => {
return (
<>
HTML - textContent - Static
>
);
};
TestHTMLTextContentStatic.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLTextContentObservable = (): JSX.Element => {
const o = $( 'danger1 ' );
const toggle = () => o ( prev => ( prev === 'danger1 ' ) ? 'danger2 ' : 'danger1 ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - textContent - Observable
>
);
};
TestHTMLTextContentObservable.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLTextContentFunction = (): JSX.Element => {
const o = $( 'danger1 ' );
const toggle = () => o ( prev => ( prev === 'danger1 ' ) ? 'danger2 ' : 'danger1 ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - textContent - Function
o ()} />
>
);
};
TestHTMLTextContentFunction.test = {
static: true,
snapshots: [
'
',
]
};
const TestHTMLDangerouslySetInnerHTMLStatic = (): JSX.Element => {
return (
<>
HTML - dangerouslySetInnerHTML - Static
danger' }} />
>
);
};
TestHTMLDangerouslySetInnerHTMLStatic.test = {
static: true,
snapshots: [
'
danger
'
]
};
const TestHTMLDangerouslySetInnerHTMLObservable = (): JSX.Element => {
const o = $( { __html: 'danger ' } );
const toggle = () => o ( prev => ( prev.__html === 'danger ' ) ? { __html: 'danger ' } : { __html: 'danger ' } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - dangerouslySetInnerHTML - Observable
>
);
};
TestHTMLDangerouslySetInnerHTMLObservable.test = {
static: false,
snapshots: [
'danger
',
'danger
'
]
};
const TestHTMLDangerouslySetInnerHTMLObservableString = (): JSX.Element => {
const o = $( 'danger ' );
const toggle = () => o ( prev => ( prev === 'danger ' ) ? 'danger ' : 'danger ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - dangerouslySetInnerHTML - Observable String
>
);
};
TestHTMLDangerouslySetInnerHTMLObservableString.test = {
static: false,
snapshots: [
'danger
',
'danger
'
]
};
const TestHTMLDangerouslySetInnerHTMLFunction = (): JSX.Element => {
const o = $( { __html: 'danger ' } );
const toggle = () => o ( prev => ( prev.__html === 'danger ' ) ? { __html: 'danger ' } : { __html: 'danger ' } );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - dangerouslySetInnerHTML - Function
o ()} />
>
);
};
TestHTMLDangerouslySetInnerHTMLFunction.test = {
static: false,
snapshots: [
'
danger
',
'danger
'
]
};
const TestHTMLDangerouslySetInnerHTMLFunctionString = (): JSX.Element => {
const o = $( 'danger ' );
const toggle = () => o ( prev => ( prev === 'danger ' ) ? 'danger ' : 'danger ' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
HTML - dangerouslySetInnerHTML - Function String
o () }} />
>
);
};
TestHTMLDangerouslySetInnerHTMLFunctionString.test = {
static: false,
snapshots: [
'
danger
',
'danger
'
]
};
const TestDirective = (): JSX.Element => {
const model = ( element, arg1, arg2 ) => {
useEffect ( () => {
const value = `${arg1} - ${arg2}`
element.value = value;
element.setAttribute ( 'value', value );
}, { sync: true } );
};
const Model = createDirective ( 'model', model );
return (
<>
Directive
>
);
};
TestDirective.test = {
static: true,
snapshots: [
' '
]
};
const TestDirectiveRegisterLocal = (): JSX.Element => {
const model = ( element, arg1, arg2 ) => {
useEffect ( () => {
const value = `${arg1} - ${arg2}`
element.value = value;
element.setAttribute ( 'value', value );
}, { sync: true } );
};
const Model = createDirective ( 'modelLocal', model );
Model.register ();
return (
<>
Directive
>
);
};
TestDirectiveRegisterLocal.test = {
static: true,
snapshots: [
' '
]
};
const TestDirectiveSingleArgument = (): JSX.Element => {
const model = ( element, arg1 ) => {
useEffect ( () => {
const value = `${arg1}`;
element.value = value;
element.setAttribute ( 'value', value );
}, { sync: true } );
};
const Model = createDirective ( 'model', model );
return (
<>
Directive - Single Argument
>
);
};
TestDirectiveSingleArgument.test = {
static: true,
snapshots: [
' '
]
};
const TestDirectiveRef = (): JSX.Element => {
const model = ( element, arg1 ) => {
useEffect ( () => {
const value = `${arg1}`;
element.value = value;
element.setAttribute ( 'value', value );
}, { sync: true } );
};
const Model = createDirective ( 'model', model );
return (
<>
Directive - Ref
>
);
};
TestDirectiveRef.test = {
static: true,
snapshots: [
' '
]
};
const TestEventClickStatic = (): JSX.Element => {
const o = $( 0 );
const increment = () => o ( prev => prev + 1 );
return (
<>
Event - Click Static
{o}
>
);
};
const TestEventClickObservable = (): JSX.Element => {
const o = $( 0 );
const onClick = $( () => {} );
const plus2 = () => o ( prev => {
onClick ( () => minus1 );
return prev + 2;
});
const minus1 = () => o ( prev => {
onClick ( () => plus2 );
return prev - 1;
});
onClick ( () => plus2 );
return (
<>
Event - Click Observable
{o}
>
);
};
const TestEventClickRemoval = (): JSX.Element => {
const o = $( 0 );
const onClick = $( () => {} );
const increment = () => o ( prev => {
onClick ( () => null );
return prev + 1;
});
onClick ( () => increment );
return (
<>
Event - Click Removal
{o}
>
);
};
const TestEventClickCaptureStatic = (): JSX.Element => {
const o = $( 0 );
const increment = () => o ( prev => prev + 1 );
return (
<>
Event - Click Capture Static
{o}
>
);
};
const TestEventClickCaptureObservable = (): JSX.Element => {
const o = $( 0 );
const onClick = $( () => {} );
const plus2 = () => o ( prev => {
onClick ( () => minus1 );
return prev + 2;
});
const minus1 = () => o ( prev => {
onClick ( () => plus2 );
return prev - 1;
});
onClick ( () => plus2 );
return (
<>
Event - Click Capture Observable
{o}
>
);
};
const TestEventClickCaptureRemoval = (): JSX.Element => {
const o = $( 0 );
const onClick = $( () => {} );
const increment = () => o ( prev => {
onClick ( () => null );
return prev + 1;
});
onClick ( () => increment );
return (
<>
Event - Click Capture Removal
{o}
>
);
};
const TestEventClickAndClickCaptureStatic = (): JSX.Element => {
const o = $( 0 );
const increment = () => o ( prev => prev + 1 );
return (
<>
Event - Click & Click Capture Static
{o}
>
);
};
const TestEventClickStopPropagation = (): JSX.Element => {
const outer = $(0);
const inner = $(0);
const incrementOuter = () => outer ( prev => prev + 1 );
const incrementInner = event => {
event.stopPropagation ();
inner ( prev => prev + 1 );
};
return (
<>
Event - Click - Stop Propagation
{outer}{inner}
>
);
};
const TestEventClickStopImmediatePropagation = (): JSX.Element => {
const outer = $(0);
const inner = $(0);
const incrementOuter = () => outer ( prev => prev + 1 );
const incrementInner = event => {
event.stopImmediatePropagation ();
inner ( prev => prev + 1 );
};
return (
<>
Event - Click - Stop Immediate Propagation
{outer}{inner}
>
);
};
const TestEventEnterStopPropagation = (): JSX.Element => {
const outer = $(0);
const inner = $(0);
const incrementOuter = () => outer ( prev => prev + 1 );
const incrementInner = event => {
event.stopPropagation ();
inner ( prev => prev + 1 );
};
return (
<>
Event - Enter - Stop Propagation
{outer}{inner}
>
);
};
const TestEventEnterStopImmediatePropagation = (): JSX.Element => {
const outer = $(0);
const inner = $(0);
const incrementOuter = () => outer ( prev => prev + 1 );
const incrementInner = event => {
event.stopImmediatePropagation ();
inner ( prev => prev + 1 );
};
return (
<>
Event - Enter - Stop Immediate Propagation
{outer}{inner}
>
);
};
const TestEventEnterAndEnterCaptureStatic = (): JSX.Element => {
const o = $( 0 );
const increment = () => o ( prev => prev + 1 );
return (
<>
Event - Enter & Enter Capture Static
{o}
>
);
};
const TestEventMiddleClickStatic = (): JSX.Element => {
const o = $( 0 );
const increment = () => o ( prev => prev + 1 );
return (
<>
Event - Middle Click Static
{o}
>
);
};
const TestEventMiddleClickCaptureStatic = (): JSX.Element => {
const o = $( 0 );
const increment = () => o ( prev => prev + 1 );
return (
<>
Event - Middle Click Capture Static
{o}
>
);
};
const TestEventTargetCurrentTarget = (): JSX.Element => {
return (
<>
Event - Target - Current Target
console.log ({ element: 'div', target: e.target, currentTarget: e.currentTarget })}>
paragraph
console.log ({ element: 'ul', target: e.target, currentTarget: e.currentTarget })}>
one
console.log ({ element: 'li', target: e.target, currentTarget: e.currentTarget })}>two
three
>
);
};
const TestABCD = (): JSX.Element => {
const AB = (): JSX.Element => {
const a = a ;
const b = b ;
const component = $( a );
const toggle = () => component ( () => ( component () === a ) ? b : a );
useInterval ( toggle, TEST_INTERVAL / 2 );
return component;
};
const CD = (): JSX.Element => {
const c = c ;
const d = d ;
const component = $( c );
const toggle = () => component ( () => ( component () === c ) ? d : c );
useInterval ( toggle, TEST_INTERVAL / 2 );
return component;
};
const ab = ;
const cd = ;
const component = $( ab );
const toggle = () => component ( () => ( component () === ab ) ? cd : ab );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Children - ABCD
{component}
>
);
};
TestABCD.test = {
static: false,
snapshots: [
'a
',
'b
',
'c
',
'd
'
]
};
const TestChildrenBoolean = (): JSX.Element => {
const Custom = ({ children }) => {
return {Number ( children )}
;
};
return (
<>
Children - Boolean
{true}
{false}
>
);
};
TestChildrenBoolean.test = {
static: true,
snapshots: [
'1
0
'
]
};
const TestChildrenSymbol = (): JSX.Element => {
const Custom = ({ children }) => {
return {typeof children}
;
};
return (
<>
Children - Boolean
{Symbol ()}
>
);
};
TestChildrenSymbol.test = {
static: true,
snapshots: [
'symbol
'
]
};
const TestChildOverReexecution = (): JSX.Element => {
const count = $(0);
const increment = () => count ( prev => Math.min ( 3, prev + 1 ) );
let executions = 0;
useTimeout ( increment, TEST_INTERVAL );
return (
<>
Child - OverReexecution
{() => executions += 1}
{count}
>
);
};
TestChildOverReexecution.test = {
static: false,
snapshots: [
'1
0',
'1
1',
'1
2',
'1
3'
]
};
const TestCleanupInner = () => {
const page = $( true );
const togglePage = () => page ( prev => !prev );
const Page1 = () => {
setTimeout ( togglePage, TEST_INTERVAL );
return (
<>
page1
Toggle Page
>
);
};
const Page2 = () => {
const bool = $( true );
const toggle = () => bool ( prev => !prev );
setTimeout ( toggle, TEST_INTERVAL );
setTimeout ( togglePage, TEST_INTERVAL * 2 );
return (
<>
page2 - true
!bool ()}>
page2 - false
Toggle
Toggle Page
>
);
};
return () => {
const Page = page () ? Page1 : Page2;
return (
<>
Cleanup - Inner
>
);
};
};
TestCleanupInner.test = {
static: false,
snapshots: [ //TODO: Double-check that this is correct
'page1
Toggle Page ',
'page2 - true
Toggle Toggle Page ',
'page2 - false
Toggle Toggle Page '
]
};
const TestCleanupInnerPortal = () => {
return (
);
};
TestCleanupInnerPortal.test = {
static: true,
snapshots: [
''
]
};
const TestContextDynamicContext = () => {
const Context = createContext ( 'default' );
const DynamicFragment = props => {
const ctx = useContext(Context);
return (
<>
{ctx}
{props.children}
{props.children}
>
);
};
return (
<>
Dynamic - Context
>
);
};
TestContextDynamicContext.test = {
static: true,
snapshots: [
'context
context
context
context
'
]
};
const TestDynamicHeading = (): JSX.Element => {
const level = $<1 | 2 | 3 | 4 | 5 | 6>(1);
const increment = () => level ( ( level () + 1 ) % 7 || 1 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
Dynamic - Heading
{() => (
Level: {level}
)}
>
);
};
TestDynamicHeading.test = {
static: false,
snapshots: [
'Level: 1 ',
'Level: 2 ',
'Level: 3 ',
'Level: 4 ',
'Level: 5 ',
'Level: 6 '
]
};
const TestDynamicObservableComponent = (): JSX.Element => {
const level = $(1);
const component = useMemo ( () => `h${level ()}` );
const increment = () => level ( ( level () + 1 ) % 7 || 1 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
Dynamic - Observable Component
Level: {level}
>
);
};
TestDynamicObservableComponent.test = {
static: false,
snapshots: [
'Level: 1 ',
'Level: 2 ',
'Level: 3 ',
'Level: 4 ',
'Level: 5 ',
'Level: 6 '
]
};
const TestDynamicFunctionComponent = (): JSX.Element => {
const level = $(1);
const component = () => `h${level ()}`;
const increment = () => level ( ( level () + 1 ) % 7 || 1 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
Dynamic - Function Component
Level: {level}
>
);
};
TestDynamicFunctionComponent.test = {
static: true,
snapshots: [
'h1'
]
};
const TestDynamicObservableProps = (): JSX.Element => {
const red = { class: 'red' };
const blue = { class: 'blue' };
const props = $(red);
const toggle = () => props ( prev => prev === red ? blue : red );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Dynamic - Observable Props
Content
>
);
};
TestDynamicObservableProps.test = {
static: false,
snapshots: [
'Content ',
'Content '
]
};
const TestDynamicFunctionProps = (): JSX.Element => {
const red = { class: 'red' };
const blue = { class: 'blue' };
const props = $(red);
const toggle = () => props ( prev => prev === red ? blue : red );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Dynamic - Function Props
Content
>
);
};
TestDynamicFunctionProps.test = {
static: false,
snapshots: [
'Content ',
'Content '
]
};
const TestDynamicObservableChildren = (): JSX.Element => {
const o = $(random ());
const update = () => o ( random () );
useInterval ( update, TEST_INTERVAL );
return (
<>
Dynamic - Observable Children
{o}
>
);
};
TestDynamicObservableChildren.test = {
static: false,
snapshots: [
'{random} '
]
};
const TestDynamicStoreProps = (): JSX.Element => {
let count = 1;
const props = store ({ class: 'red' });
const toggle = () => props.class = props.class === 'red' ? 'blue' : 'red';
setInterval ( toggle, TEST_INTERVAL );
return (
<>
Dynamic - Store Props
{() => count++}
>
);
};
TestDynamicStoreProps.test = {
staic: false,
snapshots: [
'',
''
]
};
const TestIfStatic = (): JSX.Element => {
return (
<>
If - Static
true
false
>
);
};
TestIfStatic.test = {
static: true,
snapshots: [
'true
'
]
};
const TestIfObservable = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
If - Observable
(content )
>
);
};
TestIfObservable.test = {
static: false,
snapshots: [
'(content)
',
'()
'
]
};
const TestIfFunction = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
If - Function
( o ()}>content )
>
);
};
TestIfFunction.test = {
static: false,
snapshots: [
'(content)
',
'()
'
]
};
const TestIfFunctionUntracked = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
Noop
{() => (
o ( false )}>
Close {o ()}
)}
);
};
TestIfFunctionUntracked.test = {
static: false,
snapshots: [
'NoopClose ',
'Noopfallback'
]
};
const TestIfFunctionUntrackedUnnarrowed = (): JSX.Element => {
const o = $( true );
const content = $( 0 );
const increment = () => content ( prev => ( prev + 1 ) % 3 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
If - Function Untracked Unnarrowed
({() => content ()} )
>
);
};
TestIfFunctionUntrackedUnnarrowed.test = {
static: true,
snapshots: [
'(0)
'
]
};
const TestIfFunctionUntrackedNarrowed = (): JSX.Element => {
const o = $( true );
const content = $( 0 );
const increment = () => content ( prev => ( prev + 1 ) % 3 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
If - Function Untracked Narrowed
({value => content ()} )
>
);
};
TestIfFunctionUntrackedNarrowed.test = {
static: true,
snapshots: [
'(0)
'
]
};
const TestIfNestedFunctionUnnarrowed = (): JSX.Element => {
const o = $( true );
const content = $( 0 );
const increment = () => content ( prev => ( prev + 1 ) % 3 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
If - Nested Function Unnarrowed
({() => () => content ()} )
>
);
};
TestIfNestedFunctionUnnarrowed.test = {
static: false,
snapshots: [
'(0)
',
'(1)
',
'(2)
'
]
};
const TestIfNestedFunctionNarrowed = (): JSX.Element => {
const o = $( true );
const content = $( 0 );
const increment = () => content ( prev => ( prev + 1 ) % 3 );
useInterval ( increment, TEST_INTERVAL );
return (
<>
If - Nested Function Narrowed
({value => () => content ()} )
>
);
};
TestIfNestedFunctionNarrowed.test = {
static: false,
snapshots: [
'(0)
',
'(1)
',
'(2)
'
]
};
const TestIfChildrenObservable = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
If - Children Observable
{o}
>
);
};
TestIfChildrenObservable.test = {
static: false,
snapshots: [
'{random}'
]
};
const TestIfChildrenObservableStatic = (): JSX.Element => {
const Content = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return {o ()}
};
return (
<>
If - Children Observable Static
>
);
};
TestIfChildrenObservableStatic.test = {
static: true,
snapshots: [
'{random}
'
]
};
const TestIfChildrenFunction = (): JSX.Element => {
const Content = value => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return {o ()}
};
return (
<>
If - Children Function
{Content}
>
);
};
TestIfChildrenFunction.test = {
static: true,
snapshots: [
'{random}
'
]
};
const TestIfChildrenFunctionObservable = (): JSX.Element => {
const o = $( Math.random () );
const toggle = () => o ( prev => prev ? false : Math.random () );
useInterval ( toggle, TEST_INTERVAL );
const Content = ({ value }): JSX.Element => {
return Value: {value}
};
return (
<>
If - Children Function Observable
{value => }
>
);
};
TestIfChildrenFunctionObservable.test = {
static: false,
snapshots: [
'Value: {random}
',
''
]
};
const TestIfFallbackStatic = (): JSX.Element => {
return (
<>
If - Fallback Static
Fallback!}>Children
>
);
};
TestIfFallbackStatic.test = {
static: true,
snapshots: [
'Fallback!
'
]
};
const TestIfFallbackObservable = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return Fallback: {o}
};
return (
<>
If - Fallback Observable
}>Children
>
);
};
TestIfFallbackObservable.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestIfFallbackObservableStatic = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
If - Fallback Observable Static
}>Children
>
);
};
TestIfFallbackObservableStatic.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestIfFallbackFunction = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
If - Fallback Function
Children
>
);
};
TestIfFallbackFunction.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestIfRace = () => {
const data = $<{ deep: string } | null>({ deep: 'hi' });
const visible = $(true);
setTimeout ( () => {
data ( null );
visible ( false );
});
return (
<>
If - Race
{() => data ()!.deep}
>
);
};
TestIfRace.test = {
static: false,
snapshots: [
'hi
',
''
]
};
const TestKeepAliveStatic = (): JSX.Element => {
return (
<>
KeepAlive - Static
123
>
);
};
TestKeepAliveStatic.test = {
static: true,
snapshots: [
'123
'
]
};
const TestKeepAliveObservable = (): JSX.Element => {
const o = $(true);
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
KeepAlive - Observable
{() => Math.random ()}
{() => Math.random ()}
>
);
};
TestKeepAliveObservable.test = {
static: false,
snapshots: [
'{random}
{random}
',
''
]
};
const TestTernaryStatic = (): JSX.Element => {
return (
<>
Ternary - Static
true (1)
false (1)
true (2)
false (2)
>
);
};
TestTernaryStatic.test = {
static: true,
snapshots: [
'true (1)
false (2)
'
]
};
const TestTernaryStaticInline = (): JSX.Element => {
return (
<>
Ternary - Static Inline
true (1)
false (1)
true (2)
false (2)
>
);
};
TestTernaryStaticInline.test = {
static: true,
snapshots: [
'true (1)
false (2)
'
]
};
const TestTernaryObservable = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Ternary - Observable
true
false
>
);
};
TestTernaryObservable.test = {
static: false,
snapshots: [
'true
',
'false
'
]
};
const TestTernaryObservableChildren = (): JSX.Element => {
const AB = (): JSX.Element => {
const a = a ;
const b = b ;
const component = $( a );
const toggle = () => component ( () => ( component () === a ) ? b : a );
useInterval ( toggle, TEST_INTERVAL / 2 );
return component;
};
const CD = (): JSX.Element => {
const c = c ;
const d = d ;
const component = $( c );
const toggle = () => component ( () => ( component () === c ) ? d : c );
useInterval ( toggle, TEST_INTERVAL / 2 );
return component;
};
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Ternary - Observable Children
>
);
};
TestTernaryObservableChildren.test = {
static: false,
snapshots: [
'a ',
'b ',
'c ',
'd '
]
};
const TestTernaryFunction = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Ternary - Function
!o()}>
true
false
>
);
};
TestTernaryFunction.test = {
static: false,
snapshots: [
'false
',
'true
'
]
};
const TestTernaryChildrenObservableStatic = (): JSX.Element => {
const True = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return True: {o ()}
};
const False = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return False: {o ()}
};
return (
<>
Ternary - Children Observable Static
>
);
};
TestTernaryChildrenObservableStatic.test = {
static: true,
snapshots: [
'True: {random}
False: {random}
'
]
};
const TestTernaryChildrenFunction = (): JSX.Element => {
const True = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return True: {o ()}
};
const False = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return False: {o ()}
};
return (
<>
Ternary - Children Function
{True}
{False}
{True}
{False}
>
);
};
TestTernaryChildrenFunction.test = {
static: false,
snapshots: [
'True: {random}
False: {random}
'
]
};
const TestSwitchStatic = (): JSX.Element => {
return (
<>
Switch - Static
0
1
2
default
>
);
};
TestSwitchStatic.test = {
static: true,
snapshots: [
'2
'
]
};
const TestSwitchObservable = (): JSX.Element => {
const o = $( 0 );
const toggle = () => o ( prev => ( prev + 1 ) % 4 );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Switch - Observable
0
1
2
default
>
);
};
TestSwitchObservable.test = {
static: false,
snapshots: [
'0
',
'1
',
'2
',
'default
'
]
};
const TestSwitchObservableComplex = (): JSX.Element => {
const o = $( 0 );
const toggle = () => o ( prev => ( prev + 1 ) % 4 );
const o2 = $( 2 );
const toggle2 = () => o2 ( prev => ( prev + 1 ) % 5 );
const o3 = $( 4 );
const toggle3 = () => o3 ( prev => ( prev + 1 ) % 4 );
useInterval ( toggle, TEST_INTERVAL );
useInterval ( toggle2, TEST_INTERVAL );
useInterval ( toggle3, TEST_INTERVAL );
return (
<>
Switch - Observable Complex
1 - 0
1 - 1
1 - 2
2 - 0
2 - 1
2 - 2
3 - 0
3 - 1
3 - 2
>
);
};
const TestSwitchFunction = (): JSX.Element => {
const o = $( 0 );
const toggle = () => o ( prev => ( prev + 1 ) % 4 );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Switch - Function
o ()}>
0
1
2
default
>
);
};
TestSwitchFunction.test = {
static: false,
snapshots: [
'0
',
'1
',
'2
',
'default
'
]
};
const TestSwitchCaseObservableStatic = (): JSX.Element => {
const Case = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Case: {o ()}
};
return (
<>
Switch - Case Observable Static
default
>
);
};
TestSwitchCaseObservableStatic.test = {
static: true,
snapshots: [
'Case: {random}
'
]
};
const TestSwitchCaseFunction = (): JSX.Element => {
const Case = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Case: {o ()}
};
return (
<>
Switch - Case Function
{Case}
default
>
);
};
TestSwitchCaseFunction.test = {
static: false,
snapshots: [
'Case: {random}
'
]
};
const TestSwitchDefaultObservableStatic = (): JSX.Element => {
const Default = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Default: {o ()}
};
return (
<>
Switch - Default Observable Static
case
>
);
};
TestSwitchDefaultObservableStatic.test = {
static: true,
snapshots: [
'Default: {random}
'
]
};
const TestSwitchDefaultFunction = (): JSX.Element => {
const Default = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Default: {o ()}
};
return (
<>
Switch - Default Function
case
{Default}
>
);
};
TestSwitchDefaultFunction.test = {
static: false,
snapshots: [
'Default: {random}
'
]
};
const TestSwitchFallbackObservableStatic = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
Switch - Fallback Observable Static
}>
case
>
);
};
TestSwitchFallbackObservableStatic.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestSwitchFallbackFunction = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
Switch - Fallback Function
case
>
);
};
TestSwitchFallbackFunction.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
class Component {
props: P;
state: {};
constructor ( props: P ) {
this.props = props;
this.state = {};
}
render ( props: P ): JSX.Child {
throw new Error ( 'Missing render function' );
}
static call ( thiz: Constructor, props: {} ) {
const instance = new thiz ( props );
return instance.render ( instance.props, instance.state );
}
}
class TestableComponent extends Component
{
static test = {
static: true,
snapshots: ['']
};
}
class TestComponentStatic extends TestableComponent<{}> {
render (): JSX.Element {
return (
<>
Component - Static
content
>
);
}
}
TestComponentStatic.test = {
static: true,
snapshots: [
'content
'
]
};
class TestComponentStaticProps extends TestableComponent<{ value: number }> {
render (): JSX.Element {
return (
<>
Component - Static Props
{this.props.value}
>
);
}
}
TestComponentStaticProps.test = {
static: true,
snapshots: [
'{random}
'
]
};
class TestComponentStaticRenderProps extends TestableComponent<{ value: number }> {
render ( props ): JSX.Element {
return (
<>
Component - Static Render Props
{props.value}
>
);
}
}
TestComponentStaticRenderProps.test = {
static: true,
snapshots: [
'{random}
'
]
};
class TestComponentStaticRenderState extends TestableComponent<{ value: number }> {
state: { multiplier: number };
constructor ( props ) {
super ( props );
this.state.multiplier = 0;
}
render ( props, state ): JSX.Element {
return (
<>
Component - Static Render State
{props.value * state.multiplier}
>
);
}
}
TestComponentStaticRenderState.test = {
static: true,
snapshots: [
'0
'
]
};
class TestComponentObservable extends TestableComponent<{}> {
getRandom (): number {
return random ();
}
render (): JSX.Element {
const o = $( this.getRandom () );
const randomize = () => o ( this.getRandom () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Component - Observable
{o}
>
);
}
}
TestComponentObservable.test = {
static: false,
snapshots: [
'{random}
'
]
};
class TestComponentFunction extends TestableComponent<{}> {
getRandom (): number {
return random ();
}
render (): JSX.Element {
const o = $( this.getRandom () );
const randomize = () => o ( this.getRandom () );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Component - Function
{() => o ()}
>
);
}
}
TestComponentFunction.test = {
static: false,
snapshots: [
'{random}
'
]
};
const TestTabIndexBooleanStatic = (): JSX.Element => {
return (
<>
TabIndex - Boolean - Static
true
false
>
);
};
TestTabIndexBooleanStatic.test = {
static: true,
snapshots: [
'true
false
'
]
};
const TestTabIndexBooleanObservable = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
TabIndex - Boolean - Observable
content
>
);
};
TestTabIndexBooleanObservable.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestTabIndexBooleanFunction = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
TabIndex - Boolean - Function
o ()}>content
>
);
};
TestTabIndexBooleanFunction.test = {
static: false,
snapshots: [
'content
',
'content
'
]
};
const TestForStatic = (): JSX.Element => {
const values = [1, 2, 3];
return (
<>
For - Static
{( value: number ) => {
return Value: {value}
}}
>
);
};
TestForStatic.test = {
static: true,
snapshots: [
'Value: 1
Value: 2
Value: 3
'
]
};
const TestForObservables = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const values = [v1, v2, v3];
useInterval ( () => {
v1 ( ( v1 () + 1 ) % 5 );
v2 ( ( v2 () + 1 ) % 5 );
v3 ( ( v3 () + 1 ) % 5 );
}, TEST_INTERVAL );
return (
<>
For - Observables
{( value: Observable ) => {
return Value: {value}
}}
>
);
};
TestForObservables.test = {
static: false,
snapshots: [
'Value: 1
Value: 2
Value: 3
',
'Value: 2
Value: 3
Value: 4
',
'Value: 3
Value: 4
Value: 0
',
'Value: 4
Value: 0
Value: 1
',
'Value: 0
Value: 1
Value: 2
'
]
};
const TestForObservablesStatic = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const values = [v1, v2, v3];
useInterval ( () => {
v1 ( ( v1 () + 1 ) % 5 );
v2 ( ( v2 () + 1 ) % 5 );
v3 ( ( v3 () + 1 ) % 5 );
}, TEST_INTERVAL );
return (
<>
For - Observables Static
{( value: Observable ) => {
value ();
return Value: {value ()}
}}
>
);
};
TestForObservablesStatic.test = {
static: true,
snapshots: [
'Value: 1
Value: 2
Value: 3
'
]
};
const TestForObservableObservables = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const v4 = $(4);
const v5 = $(5);
const values = $([v1, v2, v3, v4, v5]);
useInterval ( () => {
v1 ( v1 () + 1 );
v2 ( v2 () + 1 );
v3 ( v3 () + 1 );
v4 ( v4 () + 1 );
v5 ( v5 () + 1 );
values ( values ().slice ().sort ( () => .5 - random () ) );
}, TEST_INTERVAL );
return (
<>
For - Observable Observables
{( value: Observable ) => {
return Value: {value}
;
}}
>
);
};
const TestForFunctionObservables = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const values = [v1, v2, v3];
useInterval ( () => {
v1 ( ( v1 () + 1 ) % 5 );
v2 ( ( v2 () + 1 ) % 5 );
v3 ( ( v3 () + 1 ) % 5 );
}, TEST_INTERVAL );
return (
<>
For - Function Observables
values}>
{( value: Observable ) => {
return Value: {value}
}}
>
);
};
TestForFunctionObservables.test = {
static: false,
snapshots: [
'Value: 1
Value: 2
Value: 3
',
'Value: 2
Value: 3
Value: 4
',
'Value: 3
Value: 4
Value: 0
',
'Value: 4
Value: 0
Value: 1
',
'Value: 0
Value: 1
Value: 2
'
]
};
const TestForRandom = (): JSX.Element => {
const values = $([random (), random (), random ()]);
const update = () => values ( [random (), random (), random ()] );
useInterval ( update, TEST_INTERVAL );
return (
<>
For - Random Only Child
{( value: number ) => {
return Value: {value}
;
}}
>
);
};
TestForRandom.test = {
static: false,
snapshots: [
'Value: {random}
Value: {random}
Value: {random}
'
]
};
const TestForRandomOnlyChild = (): JSX.Element => {
const values = $([random (), random (), random ()]);
const update = () => values ( [random (), random (), random ()] );
useInterval ( update, TEST_INTERVAL );
return (
<>
For - Random
{( value: number ) => {
return {value}
;
}}
>
);
};
TestForRandomOnlyChild.test = {
static: false,
snapshots: [
'{random}
{random}
{random}
'
]
};
const TestForFallbackStatic = (): JSX.Element => {
return (
<>
For - Fallback Static
Fallback!}>
{( value: number ) => {
return Value: {value}
}}
>
);
};
TestForFallbackStatic.test = {
static: true,
snapshots: [
'Fallback!
'
]
};
const TestForFallbackObservable = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Fallback: {o}
>
);
};
return (
<>
For - Fallback Observable
}>
{( value: number ) => {
return Value: {value}
}}
>
);
};
TestForFallbackObservable.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestForFallbackObservableStatic = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return (
<>
Fallback: {o ()}
>
);
};
return (
<>
For - Fallback Observable Static
}>
{( value: number ) => {
return Value: {value}
}}
>
);
};
TestForFallbackObservableStatic.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestForFallbackFunction = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return (
<>
Fallback: {o ()}
>
);
};
return (
<>
For - Fallback Function
{( value: number ) => {
return Value: {value}
}}
>
);
};
TestForFallbackFunction.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestForUnkeyedStatic = (): JSX.Element => {
const values = [1, 2, 3];
return (
<>
For - Unkeyed - Static
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedStatic.test = {
static: true,
snapshots: [
'Value: 1
Value: 2
Value: 3
'
]
};
const TestForUnkeyedObservables = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const values = [v1, v2, v3];
useInterval ( () => {
v1 ( ( v1 () + 1 ) % 5 );
v2 ( ( v2 () + 1 ) % 5 );
v3 ( ( v3 () + 1 ) % 5 );
}, TEST_INTERVAL );
return (
<>
For - Unkeyed - Observables
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedObservables.test = {
static: false,
snapshots: [
'Value: 1
Value: 2
Value: 3
',
'Value: 2
Value: 3
Value: 4
',
'Value: 3
Value: 4
Value: 0
',
'Value: 4
Value: 0
Value: 1
',
'Value: 0
Value: 1
Value: 2
'
]
};
const TestForUnkeyedObservablesStatic = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const values = [v1, v2, v3];
useInterval ( () => {
v1 ( ( v1 () + 1 ) % 5 );
v2 ( ( v2 () + 1 ) % 5 );
v3 ( ( v3 () + 1 ) % 5 );
}, TEST_INTERVAL );
return (
<>
For - Unkeyed - Observables Static
{( value: ObservableReadonly ) => {
value ();
return Value: {value ()}
}}
>
);
};
TestForUnkeyedObservablesStatic.test = {
static: true,
snapshots: [
'Value: 1
Value: 2
Value: 3
'
]
};
const TestForUnkeyedObservableObservables = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const v4 = $(4);
const v5 = $(5);
const values = $([v1, v2, v3, v4, v5]);
useInterval ( () => {
v1 ( v1 () + 1 );
v2 ( v2 () + 1 );
v3 ( v3 () + 1 );
v4 ( v4 () + 1 );
v5 ( v5 () + 1 );
values ( values ().slice ().sort ( () => .5 - random () ) );
}, TEST_INTERVAL );
return (
<>
For - Unkeyed - Observable Observables
{( value: ObservableReadonly ) => {
return Value: {value}
;
}}
>
);
};
const TestForUnkeyedFunctionObservables = (): JSX.Element => {
const v1 = $(1);
const v2 = $(2);
const v3 = $(3);
const values = [v1, v2, v3];
useInterval ( () => {
v1 ( ( v1 () + 1 ) % 5 );
v2 ( ( v2 () + 1 ) % 5 );
v3 ( ( v3 () + 1 ) % 5 );
}, TEST_INTERVAL );
return (
<>
For - Unkeyed - Function Observables
values} unkeyed>
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedFunctionObservables.test = {
static: false,
snapshots: [
'Value: 1
Value: 2
Value: 3
',
'Value: 2
Value: 3
Value: 4
',
'Value: 3
Value: 4
Value: 0
',
'Value: 4
Value: 0
Value: 1
',
'Value: 0
Value: 1
Value: 2
'
]
};
const TestForUnkeyedRandom = (): JSX.Element => {
const values = $([random (), random (), random ()]);
const update = () => values ( [random (), random (), random ()] );
useInterval ( update, TEST_INTERVAL );
return (
<>
For - Unkeyed - Random
{( value: ObservableReadonly ) => {
return Value: {value}
;
}}
>
);
};
TestForUnkeyedRandom.test = {
static: false,
snapshots: [
'Value: {random}
Value: {random}
Value: {random}
'
]
};
const TestForUnkeyedRandomOnlyChild = (): JSX.Element => {
const values = $([random (), random (), random ()]);
const update = () => values ( [random (), random (), random ()] );
useInterval ( update, TEST_INTERVAL );
return (
<>
For - Unkeyed - Random Only Child
{( value: ObservableReadonly ) => {
return {value}
;
}}
>
);
};
TestForUnkeyedRandomOnlyChild.test = {
static: false,
snapshots: [
'{random}
{random}
{random}
'
]
};
const TestForUnkeyedFallbackStatic = (): JSX.Element => {
return (
<>
For - Unkeyed - Fallback Static
Fallback!} unkeyed>
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedFallbackStatic.test = {
static: true,
snapshots: [
'Fallback!
'
]
};
const TestForUnkeyedFallbackObservable = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
return (
<>
Fallback: {o}
>
);
};
return (
<>
For - Unkeyed - Fallback Observable
} unkeyed>
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedFallbackObservable.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestForUnkeyedFallbackObservableStatic = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return (
<>
Fallback: {o ()}
>
);
};
return (
<>
For - Unkeyed - Fallback Observable Static
} unkeyed>
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedFallbackObservableStatic.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestForUnkeyedFallbackFunction = (): JSX.Element => {
const Fallback = () => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return (
<>
Fallback: {o ()}
>
);
};
return (
<>
For - Unkeyed - Fallback Function
{( value: ObservableReadonly ) => {
return Value: {value}
}}
>
);
};
TestForUnkeyedFallbackFunction.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestAllowedKeyProp = (): JSX.Element => {
const Component = props => {
return {props.key}
;
};
return (
<>
Allowed - Key Prop
{h ( Component, { key: 1 } )}
{createElement ( Component, { key: 2 } )}
>
);
};
TestAllowedKeyProp.test = {
static: true,
snapshots: [
'1
2
3
'
]
};
const TestForbiddenDoubleChildren = (): JSX.Element => {
return h ( 'div', { children: 123 }, 123 );
};
TestForbiddenDoubleChildren.test = {
error: 'Providing "children" both as a prop and as rest arguments is forbidden'
};
const TestFragmentStatic = (): JSX.Element => {
return (
<>
Fragment - Static
content
>
);
};
TestFragmentStatic.test = {
static: true,
snapshots: [
'content
'
]
};
const TestFragmentStaticComponent = (): JSX.Element => {
return (
Fragment - Static Component
content
);
};
TestFragmentStaticComponent.test = {
static: true,
snapshots: [
'content
'
]
};
const TestFragmentStaticDeep = (): JSX.Element => {
return (
<>
Fragment - Static Deep
<>
first
>
<>
second
>
<>
<>
<>
<>
deep
>
>
>
>
>
);
};
TestFragmentStaticDeep.test = {
static: true,
snapshots: [
'first
second
deep
'
]
};
const TestErrorBoundary = (): JSX.Element => {
const Erroring = (): JSX.Element => {
const o = $( true );
const toggle = () => o ( prev => !prev );
useTimeout ( toggle, TEST_INTERVAL );
return useMemo ( () => {
if ( o () ) return content
;
throw new Error ( 'Custom error' );
});
};
const Fallback = ({ error, reset }): JSX.Element => {
useTimeout ( reset, TEST_INTERVAL );
return Error caught: {error.message}
;
};
return (
<>
Error Boundary
>
);
};
TestErrorBoundary.test = {
static: false,
snapshots: [
'content
',
'Error caught: Custom error
'
]
};
const TestErrorBoundaryChildrenObservableStatic = (): JSX.Element => {
const Children = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Children: {o ()}
};
const Fallback = (): JSX.Element => {
return Fallback!
;
};
return (
<>
Error Boundary - Children Observable Static
}>
>
);
};
TestErrorBoundaryChildrenObservableStatic.test = {
static: true,
snapshots: [
'Children: {random}
'
]
};
const TestErrorBoundaryChildrenFunction = (): JSX.Element => {
const Children = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Children: {o ()}
};
const Fallback = (): JSX.Element => {
return Fallback!
;
};
return (
<>
Error Boundary - Children Function
}>
{Children}
>
);
};
TestErrorBoundaryChildrenFunction.test = {
static: false,
snapshots: [
'Children: {random}
'
]
};
const TestErrorBoundaryFallbackObservableStatic = (): JSX.Element => {
const Children = (): JSX.Element => {
throw new Error ();
};
const Fallback = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
Error Boundary - Fallback Observable Static
}>
>
);
};
TestErrorBoundaryFallbackObservableStatic.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestErrorBoundaryFallbackFunction = (): JSX.Element => {
const Children = (): JSX.Element => {
throw new Error ();
};
const Fallback = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
Error Boundary - Fallback Function
>
);
};
TestErrorBoundaryFallbackFunction.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestChildren = (): JSX.Element => {
const A = ({ children }): JSX.Element => {
return {children}
;
};
const B = ({ children }): JSX.Element => {
return {children}
;
};
const C = ({ children }): JSX.Element => {
return {children}
;
};
return (
<>
Children
content
>
);
};
TestChildren.test = {
static: true,
snapshots: [
'',
]
};
const TestRef = (): JSX.Element => {
const ref = $();
useEffect ( () => {
const element = ref ();
if ( !element ) return;
element.textContent = `Got ref - Has parent: ${!!ref ()?.parentElement} - Is connected: ${!!ref ()?.isConnected}`;
}, { sync: true } );
return (
<>
Ref
content
>
);
};
TestRef.test = {
static: true,
snapshots: [
'Got ref - Has parent: true - Is connected: true
',
]
};
const TestRefs = (): JSX.Element => {
const ref1 = $();
const ref2 = $();
useEffect ( () => {
const element1 = ref1 ();
const element2 = ref2 ();
if ( !element1 ) return;
if ( !element2 ) return;
const content1 = `Got ref1 - Has parent: ${!!element1.parentElement} - Is connected: ${!!element1.isConnected}`;
const content2 = `Got ref2 - Has parent: ${!!element2.parentElement} - Is connected: ${!!element2.isConnected}`;
element1.textContent = `${content1} / ${content2}`;
}, { sync: true } );
return (
<>
Refs
content
>
);
};
TestRefs.test = {
static: true,
snapshots: [
'Got ref1 - Has parent: true - Is connected: true / Got ref2 - Has parent: true - Is connected: true
',
]
};
const TestRefsNested = (): JSX.Element => {
const ref1 = $();
const ref2 = $();
useEffect ( () => {
const element1 = ref1 ();
const element2 = ref2 ();
if ( !element1 ) return;
if ( !element2 ) return;
const content1 = `Got ref1 - Has parent: ${!!element1.parentElement} - Is connected: ${!!element1.isConnected}`;
const content2 = `Got ref2 - Has parent: ${!!element2.parentElement} - Is connected: ${!!element2.isConnected}`;
element1.textContent = `${content1} / ${content2}`;
}, { sync: true } );
return (
<>
Refs - Nested
content
>
);
};
TestRefsNested.test = {
static: true,
snapshots: [
'Got ref1 - Has parent: true - Is connected: true / Got ref2 - Has parent: true - Is connected: true
',
]
};
const TestRefUnmounting = (): JSX.Element => {
const message = $('');
const mounted = $( true );
const ref = $();
const toggle = () => mounted ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
useEffect ( () => {
const element = ref ();
if ( element ) {
message ( `Got ref - Has parent: ${!!element.parentElement} - Is connected: ${element.isConnected}` );
} else {
message ( `No ref` );
}
}, { sync: true } );
return (
<>
Ref - Unmounting
{message}
content
>
);
};
TestRefUnmounting.test = {
static: false,
wrap: false,
snapshots: [
'No ref
content
',
'Got ref - Has parent: true - Is connected: true
content
',
'Got ref - Has parent: true - Is connected: true
',
'Got ref - Has parent: true - Is connected: true
content
',
'Got ref - Has parent: true - Is connected: true
',
'Got ref - Has parent: true - Is connected: true
content
',
'Got ref - Has parent: true - Is connected: true
'
]
};
const TestRefContext = (): JSX.Element => {
const message = $('');
const Context = createContext ( 123 );
const Reffed = (): JSX.Element => {
const ref = element => message ( `Got ref - Has parent: ${!!element.parentElement} - Is connected: ${element.isConnected} - Context: ${useContext ( Context )}` );
return {message}
;
};
return (
<>
Ref - Context
>
);
};
TestRefContext.test = {
static: false,
snapshots: [
'
',
'Got ref - Has parent: true - Is connected: true - Context: 321
'
]
};
const TestRefUntrack = (): JSX.Element => {
const o = $(0);
const increment = () => o ( prev => prev + 1 );
useInterval ( increment, TEST_INTERVAL );
const Reffed = hmr ( () => {}, (): JSX.Element => {
const ref = element => element.textContent = o ();
return content
;
});
return (
<>
Ref - Untrack
>
);
};
TestRefUntrack.test = {
static: true,
snapshots: [
'0
'
]
};
const TestPromiseResolved = (): JSX.Element => {
const resolved = usePromise ( new Promise ( resolve => setTimeout ( () => resolve ( 'Loaded!' ), TEST_INTERVAL ) ) );
return (
<>
Promise - Resolved
{() => {
if ( resolved ().pending ) return Pending...
;
if ( resolved ().error ) return {resolved ().error!.message}
;
return {resolved ().value}
}}
>
);
};
TestPromiseResolved.test = {
static: false,
snapshots: [
'Pending...
',
'Loaded!
'
]
};
const TestPromiseRejected = (): JSX.Element => {
const rejected = usePromise ( new Promise ( ( _, reject ) => setTimeout ( () => reject ( 'Custom Error' ), TEST_INTERVAL ) ) );
return (
<>
Promise - Rejected
{() => {
if ( rejected ().pending ) return Pending...
;
if ( rejected ().error ) return {rejected ().error!.message}
;
return {rejected ().value}
}}
>
);
};
TestPromiseRejected.test = {
static: false,
snapshots: [
'Pending...
',
'Custom Error
'
]
};
const TestSVGStatic = (): JSX.Element => {
return (
<>
SVG - Static
>
);
};
TestSVGStatic.test = {
static: true,
snapshots: [
' '
]
};
const TestSVGStaticComplex = (): JSX.Element => {
return (
<>
SVG - Static Complex
>
);
};
const TestSVGStaticCamelCase = (): JSX.Element => {
return (
<>
SVG - Static CamelCase
>
);
};
TestSVGStaticCamelCase.test = {
static: true,
snapshots: [
' '
]
};
const TestSVGObservable = (): JSX.Element => {
const color = $(randomColor ());
const update = () => color ( randomColor () );
useInterval ( update, TEST_INTERVAL / 2 );
return (
<>
SVG - Observable
>
);
};
TestSVGObservable.test = {
static: false,
snapshots: [
' '
]
};
const TestSVGFunction = (): JSX.Element => {
const color = $(randomColor ());
const update = () => color ( randomColor () );
useInterval ( update, TEST_INTERVAL / 2 );
return (
<>
SVG - Function
color ()} stroke-width="3" fill="white">
>
);
};
TestSVGFunction.test = {
static: false,
snapshots: [
' '
]
};
const TestSVGStyleObject = (): JSX.Element => {
return (
<>
SVG - Style Object
>
);
};
TestSVGStyleObject.test = {
static: true,
snapshots: [
' '
]
};
const TestSVGStyleString = (): JSX.Element => {
return (
<>
SVG - Style String
>
);
};
TestSVGStyleString.test = {
static: true,
snapshots: [
' '
]
};
const TestSVGClassObject = (): JSX.Element => {
return (
<>
SVG - Class Object
>
);
};
TestSVGClassObject.test = {
static: true,
snapshots: [
' '
]
};
const TestSVGClassString = (): JSX.Element => {
return (
<>
SVG - Class String
>
);
};
TestSVGClassString.test = {
static: true,
snapshots: [
' '
]
};
const TestSVGAttributeRemoval = (): JSX.Element => {
const o = $( 'red' );
const toggle = () => o ( prev => ( prev === 'red' ) ? null : 'red' );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
SVG - Attribute Removal
>
);
};
TestSVGAttributeRemoval.test = {
static: false,
snapshots: [
' ',
' '
]
};
const TestTemplateExternal = (): JSX.Element => {
const Templated = template<{ class: string, color: string }> ( props => {
return (
outer inner
);
});
return (
<>
Template - External
>
);
};
TestTemplateExternal.test = {
static: true,
snapshots: [
'outer inner
outer inner
'
]
};
const TestTemplateSVG = (): JSX.Element => {
const color = $(randomColor ());
const update = () => color ( randomColor () );
useInterval ( update, TEST_INTERVAL / 2 );
const Templated = template<{ color }> ( props => {
return (
);
});
return (
<>
Template - SVG
>
);
};
TestTemplateSVG.test = {
static: false,
snapshots: [
' '
]
};
const TestContextComponents = (): JSX.Element => {
const Context = createContext ( '' );
return (
<>
Context - Components
{() => {
const value = useContext ( Context );
return {value}
;
}}
{() => {
const value = useContext ( Context );
return {value}
;
}}
{() => {
const value = useContext ( Context );
return {value}
;
}}
>
);
};
TestContextComponents.test = {
static: true,
snapshots: [
'outer
inner
outer
'
]
};
const TestContextHook = (): JSX.Element => {
const Context = createContext ( '' );
const Reader = (): JSX.Element => {
const value = useContext ( Context );
return {value}
;
};
return (
<>
Context - Hook
>
);
};
TestContextHook.test = {
static: true,
snapshots: [
'outer
inner
outer
'
]
};
const TestRenderToString = async (): Promise => {
const App = (): JSX.Element => {
const o = $(123);
return (
);
};
const expected = '';
const actual = await renderToString ( );
assert ( actual === expected, `[TestRenderToString]: Expected '${actual}' to be equal to '${expected}'` );
return actual;
};
const TestRenderToStringNested = async (): Promise => {
const App = (): JSX.Element => {
const o = $(123);
const Content = () => {
const resource = useResource ( async () => {
return await TestRenderToString ();
});
return {o}{resource.value}
;
};
return (
renderToString - Nested
);
};
const expected = 'renderToString - Nested 123<div><h3>renderToString</h3><p>123</p></div>
';
const actual = await renderToString ( );
assert ( actual === expected, `[TestRenderToStringNested]: Expected '${actual}' to be equal to '${expected}'` );
return actual;
};
const TestRenderToStringSuspense = async (): Promise => {
const App = (): JSX.Element => {
const o = $(0);
const Content = () => {
const resource = useResource ( () => {
return new Promise ( resolve => {
setTimeout ( () => {
resolve ( o ( 123 ) );
}, TEST_INTERVAL );
});
});
return {o}{resource.value}
;
};
return (
renderToString - Suspense
);
};
const expected = 'renderToString - Suspense 123123
';
const actual = await renderToString ( );
assert ( actual === expected, `[TestRenderToStringSuspense]: Expected '${actual}' to be equal to '${expected}'` );
return actual;
};
const TestRenderToStringSuspenseNested = async (): Promise => {
const App = (): JSX.Element => {
const o = $(0);
const Content = ( timeout ) => {
const resource = useResource ( () => {
return new Promise ( resolve => {
setTimeout ( () => {
resolve ( o ( 123 ) );
}, timeout );
});
});
return {o}{resource.value}
;
};
return (
renderToString - Suspense Nested
);
};
const expected = 'renderToString - Suspense Nested 123123
123123
';
const actual = await renderToString ( );
assert ( actual === expected, `[TestRenderToStringSuspenseNested]: Expected '${actual}' to be equal to '${expected}'` );
return actual;
};
const TestPortalStatic = (): JSX.Element => {
return (
<>
Portal - Static
content
>
);
};
TestPortalStatic.test = {
static: true,
snapshots: [
''
]
};
const TestPortalObservable = (): JSX.Element => {
const AB = (): JSX.Element => {
const a = a ;
const b = b ;
const component = $( a );
const toggle = () => component ( () => ( component () === a ) ? b : a );
useInterval ( toggle, TEST_INTERVAL / 2 );
return component;
};
const CD = (): JSX.Element => {
const c = c ;
const d = d ;
const component = $( c );
const toggle = () => component ( () => ( component () === c ) ? d : c );
useInterval ( toggle, TEST_INTERVAL / 2 );
return component;
};
const ab = ;
const cd = ;
const component = $( ab );
const toggle = () => component ( () => ( component () === ab ) ? cd : ab );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Portal - Observable
{component}
>
);
};
TestPortalObservable.test = {
static: true,
snapshots: [
''
]
};
const TestPortalRemoval = (): JSX.Element => {
const Inner = () => {
const log = () => console.count ( 'portal.inner' );
useInterval ( log, TEST_INTERVAL / 4 );
return content
;
};
const Portalized = () => {
const log = () => console.count ( 'portal' );
useInterval ( log, TEST_INTERVAL / 4 );
return (
);
};
const o = $( true );
const toggle = () => o ( prev => prev ? null : true );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Portal - Removal
>
);
};
TestPortalRemoval.test = {
static: true,
snapshots: [
''
]
};
const TestPortalMountObservable = (): JSX.Element => {
const div1 = document.createElement ( 'div' );
const div2 = document.createElement ( 'div' );
const mount = $(div1);
const toggle = () => mount ( prev => prev === div1 ? div2 : div1 );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Portal - Mount Observable
{div1}
{div2}
content
>
);
};
TestPortalMountObservable.test = {
static: false,
snapshots: [
'
',
'
'
]
};
const TestPortalWhenObservable = (): JSX.Element => {
const when = $(false);
const toggle = () => when ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Portal - When Observable
content
>
);
};
TestPortalWhenObservable.test = {
static: false,
snapshots: [
'content
',
''
]
};
const TestPortalWrapperStatic = (): JSX.Element => {
return (
<>
Portal - Wrapper Static
}>
content
>
);
};
TestPortalWrapperStatic.test = {
static: true,
snapshots: [
''
]
};
const TestResourceFallbackValue = (): JSX.Element => {
const resource = useResource ( () => { throw new Error ( 'Some error' ); } );
return (
<>
Resource - Fallback Value
Error! }>
resource ().value} fallback={Loading!
}>
Loaded!
Error!}>
Loading!}>
Loaded!
>
);
};
TestResourceFallbackValue.test = {
static: true,
snapshots: [
'Error!
Error!
'
]
};
const TestResourceFallbackLatest = (): JSX.Element => {
const resource = useResource ( () => { throw new Error ( 'Some error' ); } );
return (
<>
Resource - Fallback Latest
Error!}>
resource ().latest} fallback={Loading!
}>
Loaded!
Error!}>
Loading!}>
Loaded!
>
);
};
TestResourceFallbackLatest.test = {
static: true,
snapshots: [
'Error!
Error!
'
]
};
const TestSuspenseAlwaysValue = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
const resource = useResource ( () => {
return new Promise ( () => {} );
});
return Content! {resource.value}
;
};
return (
<>
Suspense - Always Value
}>
>
);
};
TestSuspenseAlwaysValue.test = {
static: true,
snapshots: [
'Loading...
'
]
};
const TestSuspenseAlwaysLatest = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
const resource = useResource ( () => {
return new Promise ( () => {} );
});
return Content! {resource.latest}
;
};
return (
<>
Suspense - Always Latest
}>
>
);
};
TestSuspenseAlwaysLatest.test = {
static: true,
snapshots: [
'Loading...
'
]
};
const TestSuspenseNever = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
return Content!
;
};
return (
<>
Suspense - Never
}>
>
);
};
TestSuspenseNever.test = {
static: true,
snapshots: [
'Content!
'
]
};
const TestSuspenseNeverRead = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
const resource = useResource ( () => {
return new Promise ( () => {} );
});
return Content!
;
};
return (
<>
Suspense - Never Read
}>
>
);
};
TestSuspenseNeverRead.test = {
static: true,
snapshots: [
'Content!
'
]
};
const TestSuspenseMiddleman = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
const o = $(0);
const branch = $(false);
const resource = useResource ( () => {
o ();
return new Promise ( resolve => {
setTimeout ( () => {
branch ( true );
}, TEST_INTERVAL / 2 );
});
});
const refetch = () => o ( prev => prev + 1 );
useInterval ( refetch, TEST_INTERVAL );
return () => {
if ( branch () ) return Middleman!
;
return Content! {resource.value}
;
};
};
return (
<>
Suspense - Middleman
}>
>
);
};
TestSuspenseMiddleman.test = {
static: false,
snapshots: [
'Loading...
',
'Middleman!
'
]
};
const TestSuspenseObservable = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
const o = $(0);
const resource = useResource ( () => {
o ();
return new Promise ( resolve => {
setTimeout ( () => {
resolve ( 123 );
}, TEST_INTERVAL / 2 );
});
});
const refetch = () => o ( prev => prev + 1 );
useInterval ( refetch, TEST_INTERVAL );
return Content! {resource.value}
;
};
return (
<>
Suspense - Observable
}>
>
);
};
TestSuspenseObservable.test = {
static: false,
snapshots: [
'Loading...
',
'Content! 123
'
]
};
const TestSuspenseWhen = (): JSX.Element => {
const Fallback = () => {
return Loading...
;
};
const Content = () => {
return Content!
;
};
const o = $(true);
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Suspense - When
}>
>
);
};
TestSuspenseWhen.test = {
static: false,
snapshots: [
'Loading...
',
'Content!
'
]
};
const TestSuspenseAlive = (): JSX.Element => {
const Fallback = () => {
return Loading ({random ()})...
;
};
const Content = () => {
return Content ({random ()})!
;
};
const o = $(true);
const toggle = () => o ( prev => !prev );
useInterval ( toggle, TEST_INTERVAL );
return (
<>
Suspense - Alive
}>
>
);
};
TestSuspenseAlive.test = {
static: false,
snapshots: [ //TODO: Test this properly, content is static but loading should be dynamic
'Loading ({random})...
',
'Content ({random})!
'
]
};
const TestSuspenseChildrenInline = (): JSX.Element => {
const resource = useResource ( () => {
return new Promise ( resolve => {
return setTimeout ( resolve, TEST_INTERVAL, 123 );
});
});
return (
<>
Suspense - Children Inline
{() => resource().value}
>
);
};
TestSuspenseChildrenInline.test = {
static: false,
snapshots: [
'Loading...',
'123'
]
};
const TestSuspenseChildrenObservableStatic = (): JSX.Element => {
const Children = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Children: {o ()}
};
const Fallback = (): JSX.Element => {
return Fallback!
;
};
return (
<>
Suspense - Children Observable Static
}>
>
);
};
TestSuspenseChildrenObservableStatic.test = {
static: true,
snapshots: [
'Children: {random}
'
]
};
const TestSuspenseChildrenFunction = (): JSX.Element => {
const Children = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Children: {o ()}
};
const Fallback = (): JSX.Element => {
return Fallback!
;
};
return (
<>
Suspense - Children Function
}>
{Children}
>
);
};
TestSuspenseChildrenFunction.test = {
static: false,
snapshots: [
'Children: {random}
'
]
};
const TestSuspenseFallbackObservableStatic = (): JSX.Element => {
const Children = (): JSX.Element => {
const resource = useResource ( () => {
return new Promise ( () => {} );
});
return children {resource.value}
;
};
const Fallback = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
Suspense - Fallback Observable Static
}>
>
);
};
TestSuspenseFallbackObservableStatic.test = {
static: true,
snapshots: [
'Fallback: {random}
'
]
};
const TestSuspenseFallbackFunction = (): JSX.Element => {
const Children = (): JSX.Element => {
const resource = useResource ( () => {
return new Promise ( () => {} );
});
return children {resource.value}
;
};
const Fallback = (): JSX.Element => {
const o = $( String ( random () ) );
const randomize = () => o ( String ( random () ) );
useInterval ( randomize, TEST_INTERVAL );
o ();
return Fallback: {o ()}
};
return (
<>
Suspense - Fallback Function
>
);
};
TestSuspenseFallbackFunction.test = {
static: false,
snapshots: [
'Fallback: {random}
'
]
};
const TestSuspenseCleanup = (): JSX.Element => {
const ChildrenLoop = () => {
const resource = useResource ( () => {
return new Promise ( () => {} );
});
return Loop! {resource.value}
;
};
const ChildrenPlain = () => {
return Loaded!
;
};
const Children = (): JSX.Element => {
const o = $(true);
const toggle = () => o ( prev => !prev );
setTimeout ( toggle, TEST_INTERVAL );
return (
);
};
const Fallback = (): JSX.Element => {
return Loading...
;
};
return (
<>
Suspense - Cleanup
}>
>
);
};
TestSuspenseCleanup.test = {
static: false,
snapshots: [
'Loading...
',
'Loaded!
'
]
};
const TestLazy = (): JSX.Element => {
const Component = (): JSX.Element => {
return Loaded!
;
}
const Fallback = (): JSX.Element => {
return Loading...
;
};
const lazyFetcher = () => new Promise<{ default: JSX.Component }> ( resolve => setTimeout ( () => resolve ( { default: Component } ), TEST_INTERVAL ) );
const LazyComponent = lazy ( lazyFetcher );
return (
<>
Lazy
}>
>
);
};
TestLazy.test = {
static: false,
snapshots: [
'Loading...
',
'Loaded!
'
]
};
const TestNestedArrays = (): JSX.Element => {
const items = $([ 0, 1, 2 ]);
const activeItem = $(1);
const incrementItems = () => {
items ( items => [...items, items.length] );
activeItem ( item => item + 1 );
};
setTimeout ( incrementItems, TEST_INTERVAL );
setTimeout ( incrementItems, TEST_INTERVAL * 2 );
return (
<>
Nested Arrays
Increment
{item => {
return (
<>
activeItem () === item}>
test
{item}
>
);
}}
>
);
};
TestNestedArrays.test = {
static: false,
snapshots: [
'Increment ',
'Increment ',
'Increment '
]
};
const TestNestedIfs = (): JSX.Element => {
return (
<>
1
2
Footer
>
);
};
TestNestedIfs.test = {
static: true,
snapshots: [
'1
2
Footer
'
]
};
const TestNestedIfsLazy = (): JSX.Element => {
const o = $(false);
const toggle = () => o ( prev => !prev );
useTimeout ( toggle, TEST_INTERVAL );
return (
<>
before
inner
after
>
);
};
TestNestedIfsLazy.test = {
static: false,
snapshots: [
'before
after
',
'before
inner
after
',
]
};
const TestHMRFor = () => {
const o = $([ 1, 2, 3 ]);
const update = () => o ([ 2, 3, 4 ]);
setTimeout ( update, TEST_INTERVAL );
const Button = hmr ( () => {}, ({ value, index }) => {
return {value}, {index} ;
});
return (
<>
HMR - For
prev
{( item, index ) => (
)}
next
>
);
};
TestHMRFor.test = {
static: false,
snapshots: [
'prev
1, 0 2, 1 3, 2 next
',
'prev
2, 0 3, 1 4, 2 next
'
]
};
const Test = (): JSX.Element => {
TestRenderToStringNested ();
TestRenderToString ();
TestRenderToStringNested ();
TestRenderToStringSuspense ();
TestRenderToStringSuspenseNested ();
return (
<>
{/* */}
{/* */}
{/* */}
{/* */}
>
);
};
/* RENDER */
render ( , document.getElementById ( 'app' ) );