Skip to content

Commit

Permalink
Params are passed to routeLoading too
Browse files Browse the repository at this point in the history
  • Loading branch information
ItalyPaleAle authored Jun 17, 2021
1 parent 6a4e3b3 commit 5febf15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ const unsubscribeLoc = loc.subscribe(async (newLoc) => {
route: routesList[i].path,
location: newLoc.location,
querystring: newLoc.querystring,
userData: routesList[i].userData
userData: routesList[i].userData,
params: (match && typeof match == 'object' && Object.keys(match).length) ? match : null
}
// Check if the route can be loaded - if all conditions succeed
Expand Down
14 changes: 7 additions & 7 deletions test/cases/01-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,11 @@ describe('<Router> component', function() {
browser
.url(browser.launchUrl)
.waitForElementPresent('#logbox')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/","location":"/","querystring":""}\nrouteLoaded - {"route":"/","location":"/","querystring":"","name":"Home","params":null}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/","location":"/","querystring":"","params":null}\nrouteLoaded - {"route":"/","location":"/","querystring":"","params":null,"name":"Home"}')

browser.url(browser.launchUrl + '/#/hello/svelte')
.waitForElementPresent('#logbox')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/","location":"/","querystring":""}\nrouteLoaded - {"route":"/","location":"/","querystring":"","name":"Home","params":null}\nrouteLoading - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":""}\nrouteLoaded - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":"","name":"Name","params":{"first":"svelte","last":null}}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/","location":"/","querystring":"","params":null}\nrouteLoaded - {"route":"/","location":"/","querystring":"","params":null,"name":"Home"}\nrouteLoading - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":"","params":{"first":"svelte","last":null}}\nrouteLoaded - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":"","params":{"first":"svelte","last":null},"name":"Name"}')

browser.end()
})
Expand All @@ -297,7 +297,7 @@ describe('<Router> component', function() {
.click('p#nameparams', () => {
browser
.waitForElementPresent('#logbox')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":""}\nrouteLoaded - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":"","name":"Name","params":{"first":"svelte","last":null}}\nrouteEvent - {"action":"hi","params":{"first":"svelte","last":null}}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":"","params":{"first":"svelte","last":null}}\nrouteLoaded - {"route":"/hello/:first/:last?","location":"/hello/svelte","querystring":"","params":{"first":"svelte","last":null},"name":"Name"}\nrouteEvent - {"action":"hi","params":{"first":"svelte","last":null}}')

browser.end()
})
Expand Down Expand Up @@ -332,12 +332,12 @@ describe('<Router> component', function() {
.expect.element('#pleasewait').text.to.equal('Please wait…')
browser.expect.element('#loadingmessage').text.to.equal('Message is secret')
browser.waitForElementPresent('#lucky')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"}}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"name":"Loading","params":{"message":"secret"}}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"name":"Lucky","params":null}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"params":null}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"params":{"message":"secret"},"name":"Loading"}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"params":null,"name":"Lucky"}')

// Condition always fails
browser.url(browser.launchUrl + '/#/lucky?pass=0')
.waitForElementPresent('#logbox')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"}}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"name":"Loading","params":{"message":"secret"}}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"name":"Lucky","params":null}\nconditionsFailed - {"route":"/lucky","location":"/lucky","querystring":"pass=0","userData":{"foo":"bar"}}\nrouteLoading - {"route":"/wild/*","location":"/wild/conditions-failed","querystring":""}\nrouteLoaded - {"route":"/wild/*","location":"/wild/conditions-failed","querystring":"","name":"Wild","params":{"wild":"conditions-failed"}}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"params":null}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"params":{"message":"secret"},"name":"Loading"}\nrouteLoaded - {"route":"/lucky","location":"/lucky","querystring":"pass=1","userData":{"foo":"bar"},"params":null,"name":"Lucky"}\nconditionsFailed - {"route":"/lucky","location":"/lucky","querystring":"pass=0","userData":{"foo":"bar"},"params":null}\nrouteLoading - {"route":"/wild/*","location":"/wild/conditions-failed","querystring":"","params":{"wild":"conditions-failed"}}\nrouteLoaded - {"route":"/wild/*","location":"/wild/conditions-failed","querystring":"","params":{"wild":"conditions-failed"},"name":"Wild"}')

browser.end()
})
Expand Down Expand Up @@ -365,12 +365,12 @@ describe('<Router> component', function() {
browser
.url(browser.launchUrl + '/#/catalog/3')
.waitForElementPresent('#logbox')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/catalog/:id?","location":"/catalog/3","querystring":""}\nrouteLoaded - {"route":"/catalog/:id?","location":"/catalog/3","querystring":"","name":"Catalog","params":{"id":"3"}}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/catalog/:id?","location":"/catalog/3","querystring":"","params":{"id":"3"}}\nrouteLoaded - {"route":"/catalog/:id?","location":"/catalog/3","querystring":"","params":{"id":"3"},"name":"Catalog"}')
browser.expect.element('#previous').attribute('href').to.endsWith('#/catalog/2')
browser.expect.element('#next').attribute('href').to.endsWith('#/catalog/4')
browser.click('#next', () => {
browser.waitForElementVisible('#logbox')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/catalog/:id?","location":"/catalog/3","querystring":""}\nrouteLoaded - {"route":"/catalog/:id?","location":"/catalog/3","querystring":"","name":"Catalog","params":{"id":"3"}}\nrouteLoading - {"route":"/catalog/:id?","location":"/catalog/4","querystring":""}\nrouteLoaded - {"route":"/catalog/:id?","location":"/catalog/4","querystring":"","name":"Catalog","params":{"id":"4"}}')
.expect.element('#logbox').text.to.equal('routeLoading - {"route":"/catalog/:id?","location":"/catalog/3","querystring":"","params":{"id":"3"}}\nrouteLoaded - {"route":"/catalog/:id?","location":"/catalog/3","querystring":"","params":{"id":"3"},"name":"Catalog"}\nrouteLoading - {"route":"/catalog/:id?","location":"/catalog/4","querystring":"","params":{"id":"4"}}\nrouteLoaded - {"route":"/catalog/:id?","location":"/catalog/4","querystring":"","params":{"id":"4"},"name":"Catalog"}')
browser.expect.element('#previous').attribute('href').to.endsWith('#/catalog/3')
browser.expect.element('#next').attribute('href').to.endsWith('#/catalog/5')
})
Expand Down

0 comments on commit 5febf15

Please sign in to comment.