swaf/test/assets/views/LocalsTest.svelte

26 lines
1.4 KiB
Svelte
Raw Permalink Normal View History

<script lang="ts">
import {locals} from '../ts/stores.js';
import Test from "./Test.svelte";
//TODO: binding tests
</script>
<Test name="$locals" actualValue={$locals} not expectedValue={undefined}/>
<Test name="\$locals.route" actualValue={$locals.route} not expectedValue={undefined}/>
<Test name="$locals escaping" actualValue="\$locals.route" not expectedValue="$locals('route')"/>
<Test name="$locals not escaping" actualValue="$locals.route" expectedValue="$locals('route')"/>
<Test name="$locals escaping" actualValue={`{\\$locals.escaped}`} not expectedValue={`{$locals('escaped')}`}/>
<Test name="$locals not escaping" actualValue={`{$locals.escaped}`} expectedValue={`{$locals('escaped')}`}/>
<!-- Inspecting values -->
<Test name="\$locals.dump string" actualValue={$locals.dump('bonjour')} expectedValue="'bonjour'"/>
<Test name="\$locals.dump NaN" actualValue={$locals.dump(NaN)} expectedValue="NaN"/>
<!-- Nested locals calls -->
<Test name="\$locals.dump \$locals.name" actualValue={$locals.dump($locals.app)} not expectedValue={undefined}/>
<Test name="\$locals.dump \$locals.app.name" actualValue={$locals.dump($locals.app.name)} expectedValue="'Example App'"/>
<!-- Routes (url building) -->
<Test name="\$locals.route home" actualValue={$locals.route('home')} expectedValue="/"/>
<Test name="\$locals.route auth" actualValue={$locals.route('auth')} expectedValue="/auth/"/>