Skip to content

Commit cd4ba06

Browse files
author
pynnl
committed
add test: matches
1 parent b10a04f commit cd4ba06

File tree

5 files changed

+51
-31
lines changed

5 files changed

+51
-31
lines changed

cypress/integration/main.spec.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
function checkRoutes (arr, ...args) {
1+
function checkVisible (name, arr, ...args) {
22
for (let e of args)
3-
cy.get(`.route:contains(${e})`).should('be.visible')
3+
cy.get(`.${name}:contains(${e})`).should('be.visible')
44

55
for (let e of arr.filter(e => !args.includes(e)))
6-
cy.get(`.route:contains(${e})`).should('not.be.visible')
6+
cy.get(`.${name}:contains(${e})`).should('not.be.visible')
7+
}
8+
9+
function checkRoutes () {
10+
checkVisible('route', ...arguments)
711
}
812

913
function checkProperty (key, value) {
@@ -168,3 +172,20 @@ it('active', () => {
168172
checkProperty('href', '#/active/route2/route3')
169173
checkRoutes(arr, 2, 3)
170174
})
175+
176+
it('matches', () => {
177+
let checkProp = (...args) => checkVisible('property', ...args)
178+
let arr = ['/', 'matches', '/route1', '/route2', '/route3']
179+
180+
cy.visit('#/matches')
181+
checkProp(arr, '/', 'matches')
182+
183+
cy.visit('#/matches/route1')
184+
checkProp(arr, '/', 'matches', '/route1')
185+
186+
cy.visit('#/matches/route2')
187+
checkProp(arr, '/', 'matches', '/route2')
188+
189+
cy.visit('#/matches/route2/route3')
190+
checkProp(arr, '/', 'matches', '/route2', '/route3')
191+
})

test/src/components/Link.svelte

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Redirect, { schema as _Redirect } from './tests/Redirect.svelte'
88
import Params, { schema as _Params } from './tests/Params.svelte'
99
import Query from './tests/Query.svelte'
1010
import Active, { schema as _Active } from './tests/Active.svelte'
11+
import Matches, { schema as _Matches } from './tests/Matches.svelte'
1112

1213
routes.set({
1314
'/': {
@@ -19,7 +20,8 @@ routes.set({
1920
'redirect': { $$component: Redirect, ..._Redirect },
2021
'params': { $$component: Params, ..._Params },
2122
'query': Query,
22-
'active': { $$component: Active, ..._Active }
23+
'active': { $$component: Active, ..._Active },
24+
'matches': { $$component: Matches, ..._Matches }
2325
}
2426
})
2527

test/src/tests/Active.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export let schema = {
1515
}
1616
</script>
1717

18-
<Navigator route='{$routes[`/`][`active`]}'/>
18+
<Navigator route='{$routes[`/`][`active`]}' deep={true} exact={true}/>
1919
<div>
2020
<Property key='href' value={$active.$$href}/>
2121
<Router deep={true}/>

test/src/tests/Matches.svelte

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<script context='module'>
2+
import { routes, matches } from '../../../src'
3+
import Route1 from '../components/Route1.svelte'
4+
import Route2 from '../components/Route2.svelte'
5+
import Route3 from '../components/Route3.svelte'
6+
import Navigator from '../components/Navigator.svelte'
7+
import Property from '../components/Property.svelte'
8+
9+
export let schema = {
10+
'/route1': Route1,
11+
'/route2': {
12+
$$component: Route2,
13+
'/route3': Route3
14+
}
15+
}
16+
</script>
17+
18+
<Navigator route='{$routes[`/`][`matches`]}' deep={true} exact={true}/>
19+
<div>
20+
{#each $matches as e}
21+
<Property value={e.$$pathname}/>
22+
{/each}
23+
</div>

0 commit comments

Comments
 (0)