From b9c1b49810ba87935d0d2f0d798e6ee37c52bfab Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Fri, 17 Aug 2018 15:01:18 +0300 Subject: [PATCH] chore: minor fixes after refactor --- src/services/HistoryService.ts | 10 +++++----- src/services/__tests__/history.service.test.ts | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/services/HistoryService.ts b/src/services/HistoryService.ts index 2ed1fbac..da48f946 100644 --- a/src/services/HistoryService.ts +++ b/src/services/HistoryService.ts @@ -4,10 +4,6 @@ import { IS_BROWSER } from '../utils/'; const EVENT = 'hashchange'; -function isSameHash(a: string, b: string): boolean { - return a === b || '#' + a === b || a === '#' + b; -} - export class HistoryService { private _emiter; @@ -21,6 +17,9 @@ export class HistoryService { } linkForId(id: string) { + if (!id) { + return ''; + } return '#' + id; } @@ -52,7 +51,7 @@ export class HistoryService { return; } - if (id == null || isSameHash(id, this.currentId)) { + if (id == null || id === this.currentId) { return; } if (rewriteHistory) { @@ -65,6 +64,7 @@ export class HistoryService { return; } window.history.pushState(null, '', window.location.href.split('#')[0] + this.linkForId(id)); + this.emit(); } } diff --git a/src/services/__tests__/history.service.test.ts b/src/services/__tests__/history.service.test.ts index 011378b3..753340d0 100644 --- a/src/services/__tests__/history.service.test.ts +++ b/src/services/__tests__/history.service.test.ts @@ -31,4 +31,8 @@ describe('History service', () => { test('should return correct link for id', () => { expect(history.linkForId('testid')).toEqual('#testid'); }); + + test('should return empty link for empty id', () => { + expect(history.linkForId('')).toEqual(''); + }); });