Skip to content

Commit

Permalink
updated: sync with main
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Oct 20, 2023
1 parent fcc9234 commit 17e7eac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 45 deletions.
3 changes: 2 additions & 1 deletion src/components/route-hoc.riot
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
this.callLifecycleProperty('onBeforeMount', route)
this.update({route})
if (route.hash) loc.hash = route.hash; // make browser scroll to fragment
// make browser scroll to fragment
if (route.hash && loc.hash !== route.hash) loc.hash = route.hash
this.callLifecycleProperty('onMounted', route)
},
callLifecycleProperty(method, ...params) {
Expand Down
43 changes: 0 additions & 43 deletions test/misc-dom.spec.js

This file was deleted.

20 changes: 19 additions & 1 deletion test/standalone-history-dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('standalone history', function () {
<a href="/user">User</a>
<a href="/goodbye">goodbye</a>
<a href="/user/gianluca">Username</a>
<a href="/hello#anchor">Anchor</a>
</nav>
`
teardown = initDomListeners($('nav')[0])
Expand Down Expand Up @@ -50,8 +51,25 @@ describe('standalone history', function () {
done()
})

const [a] = $('nav > a:last-of-type')
const [a] = $('nav > a:nth-child(4)')

fireEvent(a, 'click')
})

it('hash links are supported', async () => {
const onRoute = spy()
const hello = route('/hello(/?[?#].*)?').on.value(onRoute)

const [a] = $('nav > a:nth-child(5)')

fireEvent(a, 'click')

await sleep()

expect(onRoute).to.have.been.called
expect(window.location.pathname).to.be.equal('/hello')
expect(window.location.hash).to.be.equal('#anchor')

hello.end()
})
})

0 comments on commit 17e7eac

Please sign in to comment.