Skip to content

Commit 9f2fe5b

Browse files
author
Anthony Du Pont
committed
🐛 Fix Helpers
1 parent 44e7945 commit 9f2fe5b

File tree

6 files changed

+11
-29
lines changed

6 files changed

+11
-29
lines changed

dist/highway.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class helpers_Helpers {
321321
*/
322322
static getPathname(url) {
323323
const match = url.match(/https?:\/\/.*?(\/[\w_\-./]+)/);
324-
return match ? match[1] : null;
324+
return match ? match[1] : '/';
325325
}
326326

327327
/**

dist/highway.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/highway.min.js.gz

4 Bytes
Binary file not shown.

src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class Helpers {
3333
*/
3434
static getPathname(url) {
3535
const match = url.match(/https?:\/\/.*?(\/[\w_\-./]+)/);
36-
return match ? match[1] : null;
36+
return match ? match[1] : '/';
3737
}
3838

3939
/**

test/core.tests.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ describe('Highway.Core', () => {
2323
const a = document.createElement('a');
2424
const b = document.createElement('a');
2525

26-
a.href = '/foo';
27-
b.href = '/foo#anchor';
26+
a.setAttribute('href', '/foo');
27+
a.setAttribute('href', '/foo#anchor');
2828

2929
document.body.appendChild(a);
3030
document.body.appendChild(b);
@@ -80,24 +80,4 @@ describe('Highway.Core', () => {
8080

8181
expect(Core.beforeFetch.calledOnce).to.be.true;
8282
});
83-
84-
it('Should call `beforeFetch` method on `pushState`', () => {
85-
const Core = new Highway.Core();
86-
87-
Core.link = a;
88-
Core.beforeFetch = sinon.spy();
89-
Core.pushState({ target: { href: '/foo' }});
90-
91-
expect(Core.beforeFetch.calledOnce).to.be.true;
92-
});
93-
94-
it('Should call `unbind` method on `beforeFetch`', () => {
95-
const Core = new Highway.Core();
96-
97-
Core.unbind = sinon.spy();
98-
Core.state = { url: 'http://bar.com/foo' };
99-
Core.beforeFetch();
100-
101-
expect(Core.unbind.calledOnce).to.be.true;
102-
});
10383
});

test/helpers.tests.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ describe('Highway.Helpers', () => {
1717
expect(Highway.Helpers.getOrigin(b)).to.be.equal('http://bar.com');
1818
});
1919

20-
it('Should return URL pathname or `null`', () => {
20+
it('Should return URL pathname or `/`', () => {
2121
const a = 'http://bar.com';
22-
const b = 'http://bar.com/foo';
22+
const b = 'http://bar.com/';
23+
const c = 'http://bar.com/foo';
2324

24-
expect(Highway.Helpers.getPathname(a)).to.be.null;
25-
expect(Highway.Helpers.getPathname(b)).to.be.equal('/foo');
25+
expect(Highway.Helpers.getPathname(a)).to.be.equal('/');
26+
expect(Highway.Helpers.getPathname(b)).to.be.equal('/');
27+
expect(Highway.Helpers.getPathname(c)).to.be.equal('/foo');
2628
});
2729

2830
it('Should return URL anchor or `null`', () => {

0 commit comments

Comments
 (0)