import { createUrlTracker , IUrlTracker } from './url_tracker' ; import { StubBrowserStorage } from 'test_utils/stub_browser_storage' ; import { createMemoryHistory , History } from 'history' ; describe ( 'urlTracker' , ( ) => { let storage ; let history ; let urlTracker ; beforeEach ( ( ) => { storage = new StubBrowserStorage ( ) ; history = createMemoryHistory ( ) ; urlTracker = createUrlTracker ( 'test' , storage ) ; } ) ; it ( 'should return null if no tracked url' , ( ) => { expect ( urlTracker . getTrackedUrl ( ) ) . toBeNull ( ) ; } ) ; it ( 'should return last tracked url' , ( ) => { urlTracker . trackUrl ( 'http://localhost:4200' ) ; urlTracker . trackUrl ( 'http://localhost:4201' ) ; urlTracker . trackUrl ( 'http://localhost:4202' ) ; expect ( urlTracker . getTrackedUrl ( ) ) . toBe ( 'http://localhost:4202' ) ; } ) ; it ( 'should listen to history and track updates' , ( ) => { const stop = urlTracker . startTrackingUrl ( history ) ; expect ( urlTracker . getTrackedUrl ( ) ) . toBe ( '/' ) ; history . push ( '/1' ) ; history . replace ( '/2' ) ; expect ( urlTracker . getTrackedUrl ( ) ) . toBe ( '/2' ) ; stop ( ) ; history . replace ( '/3' ) ; expect ( urlTracker . getTrackedUrl ( ) ) . toBe ( '/2' ) ; } ) ; } ) ;