-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a8fb8c
commit acf74bd
Showing
3 changed files
with
39 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,48 @@ | ||
import { beforeEach, afterEach, describe, expect, test, vi } from 'vitest' | ||
import * as isBrowser from '@/utilities/isBrowser' | ||
import { describe, expect, test, vi } from 'vitest' | ||
import { createRouterNavigation } from '@/utilities/routerNavigation' | ||
import { random } from '@/utilities/testHelpers' | ||
import * as utilities from '@/utilities/updateBrowserUrl' | ||
|
||
describe('createRouterNavigation', () => { | ||
describe('when isBrowser is true', () => { | ||
test('when go is called, forwards call to window history', () => { | ||
vi.spyOn(window.history, 'go') | ||
test('when go is called, forwards call to window history', () => { | ||
vi.spyOn(window.history, 'go') | ||
|
||
const delta = random.number({ min: 0, max: 100 }) | ||
const history = createRouterNavigation() | ||
const delta = random.number({ min: 0, max: 100 }) | ||
const history = createRouterNavigation() | ||
|
||
history.go(delta) | ||
history.go(delta) | ||
|
||
expect(window.history.go).toHaveBeenCalledWith(delta) | ||
}) | ||
|
||
test('when back is called, forwards call to window history', () => { | ||
vi.spyOn(window.history, 'back') | ||
|
||
const history = createRouterNavigation() | ||
|
||
history.back() | ||
|
||
expect(window.history.back).toHaveBeenCalledOnce() | ||
}) | ||
|
||
test('when forward is called, forwards call to window history', () => { | ||
vi.spyOn(window.history, 'forward') | ||
|
||
const history = createRouterNavigation() | ||
|
||
history.forward() | ||
|
||
expect(window.history.forward).toHaveBeenCalledOnce() | ||
}) | ||
|
||
test('when update is called, calls updateBrowserUrl', () => { | ||
vi.spyOn(utilities, 'updateBrowserUrl') | ||
|
||
const url = random.number().toString() | ||
const history = createRouterNavigation() | ||
|
||
history.update(url) | ||
|
||
expect(utilities.updateBrowserUrl).toHaveBeenCalledWith(url) | ||
}) | ||
expect(window.history.go).toHaveBeenCalledWith(delta) | ||
}) | ||
|
||
describe('when isBrowser is false', () => { | ||
beforeEach(() => { | ||
vi.spyOn(isBrowser, 'isBrowser').mockImplementation(() => false) | ||
}) | ||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
test('when go is called, does nothing', () => { | ||
vi.spyOn(window.history, 'go') | ||
|
||
const delta = random.number({ min: 0, max: 100 }) | ||
const history = createRouterNavigation() | ||
|
||
history.go(delta) | ||
test('when back is called, forwards call to window history', () => { | ||
vi.spyOn(window.history, 'back') | ||
|
||
expect(window.history.go).toHaveBeenCalledTimes(0) | ||
}) | ||
const history = createRouterNavigation() | ||
|
||
test('when back is called, does nothing', () => { | ||
vi.spyOn(window.history, 'back') | ||
history.back() | ||
|
||
const history = createRouterNavigation() | ||
|
||
history.back() | ||
|
||
expect(window.history.back).toHaveBeenCalledTimes(0) | ||
}) | ||
expect(window.history.back).toHaveBeenCalledOnce() | ||
}) | ||
|
||
test('when forward is called, does nothing', () => { | ||
vi.spyOn(window.history, 'forward') | ||
test('when forward is called, forwards call to window history', () => { | ||
vi.spyOn(window.history, 'forward') | ||
|
||
const history = createRouterNavigation() | ||
const history = createRouterNavigation() | ||
|
||
history.forward() | ||
history.forward() | ||
|
||
expect(window.history.forward).toHaveBeenCalledTimes(0) | ||
}) | ||
expect(window.history.forward).toHaveBeenCalledOnce() | ||
}) | ||
|
||
test('when update is called, calls updateBrowserUrl', () => { | ||
vi.spyOn(utilities, 'updateBrowserUrl') | ||
test('when update is called, calls updateBrowserUrl', () => { | ||
vi.spyOn(utilities, 'updateBrowserUrl') | ||
|
||
const url = random.number().toString() | ||
const history = createRouterNavigation() | ||
const url = random.number().toString() | ||
const history = createRouterNavigation() | ||
|
||
history.update(url) | ||
history.update(url) | ||
|
||
expect(utilities.updateBrowserUrl).toHaveBeenCalledWith(url) | ||
}) | ||
expect(utilities.updateBrowserUrl).toHaveBeenCalledWith(url) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { createRouterNavigation } from '@/utilities/routerNavigation' | ||
|
||
describe('createRouterNavigation', () => { | ||
test('is not implemented, and throws exception', () => { | ||
expect(() => createRouterNavigation()).toThrowError('not implemented') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters