From 5febf1589fa6cb570968f566a1f863a19282c4b7 Mon Sep 17 00:00:00 2001 From: "Alessandro (Ale) Segala" <43508+ItalyPaleAle@users.noreply.github.com> Date: Thu, 17 Jun 2021 00:32:03 +0000 Subject: [PATCH] Params are passed to routeLoading too --- Router.svelte | 3 ++- test/cases/01-routing.test.js | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Router.svelte b/Router.svelte index bb10782..034cd20 100644 --- a/Router.svelte +++ b/Router.svelte @@ -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 diff --git a/test/cases/01-routing.test.js b/test/cases/01-routing.test.js index b537927..7490cfa 100644 --- a/test/cases/01-routing.test.js +++ b/test/cases/01-routing.test.js @@ -280,11 +280,11 @@ describe(' 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() }) @@ -297,7 +297,7 @@ describe(' 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() }) @@ -332,12 +332,12 @@ describe(' 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() }) @@ -365,12 +365,12 @@ describe(' 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') })