Skip to content

Commit

Permalink
removed describes for tests related to this PR
Browse files Browse the repository at this point in the history
  • Loading branch information
stackoverfloweth committed Jan 7, 2024
1 parent 481de43 commit e52fa3d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 56 deletions.
74 changes: 36 additions & 38 deletions src/utilities/createRouter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
import { describe, expect, test } from 'vitest'
import { expect, test } from 'vitest'
import { createRouter } from '@/utilities/createRouter'
import { component } from '@/utilities/testHelpers'

describe('createRouter', () => {
test('initial route is set', () => {
const root = {
name: 'root',
component,
path: '/',
}
test('initial route is set', () => {
const root = {
name: 'root',
component,
path: '/',
}

const { route } = createRouter([root], {
initialUrl: root.path,
})

expect(route.matched).toMatchObject(root)
const { route } = createRouter([root], {
initialUrl: root.path,
})

test('throws error if route is not matched', () => {
expect(() => createRouter([], {
initialUrl: '/foo',
})).toThrowError('not implemented')
expect(route.matched).toMatchObject(root)
})

test('throws error if route is not matched', () => {
expect(() => createRouter([], {
initialUrl: '/foo',
})).toThrowError('not implemented')
})

test('updates the route when navigating', async () => {
const first = {
name: 'first',
component,
path: '/first',
}

const second = {
name: 'second',
component,
path: '/second',
}

const { push, route } = createRouter([first, second], {
initialUrl: first.path,
})

test('updates the route when navigating', async () => {
const first = {
name: 'first',
component,
path: '/first',
}

const second = {
name: 'second',
component,
path: '/second',
}

const { push, route } = createRouter([first, second], {
initialUrl: first.path,
})
expect(route.matched).toMatchObject(first)

expect(route.matched).toMatchObject(first)
await push(second.path)

await push(second.path)

expect(route.matched).toMatchObject(second)
})
expect(route.matched).toMatchObject(second)
})
24 changes: 11 additions & 13 deletions src/utilities/getInitialUrl.browser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import { describe, expect, test, vi } from 'vitest'
import { expect, test, vi } from 'vitest'
import { random } from '.'
import { getInitialUrl } from '@/utilities/getInitialUrl'

describe('getInitialUrl', () => {
test('given value for initial route, returns value', () => {
const initialRoute = random.number().toString()
test('given value for initial route, returns value', () => {
const initialRoute = random.number().toString()

const response = getInitialUrl(initialRoute)
const response = getInitialUrl(initialRoute)


expect(response).toBe(initialRoute)
})
expect(response).toBe(initialRoute)
})

test('defaults to window.location', () => {
const initialRoute = random.number().toString()
vi.stubGlobal('location', initialRoute)
test('defaults to window.location', () => {
const initialRoute = random.number().toString()
vi.stubGlobal('location', initialRoute)

const response = getInitialUrl()
const response = getInitialUrl()

expect(response).toBe(initialRoute)
})
expect(response).toBe(initialRoute)
})
8 changes: 3 additions & 5 deletions src/utilities/getInitialUrl.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { describe, expect, test } from 'vitest'
import { expect, test } from 'vitest'
import { getInitialUrl } from '@/utilities/getInitialUrl'

describe('getInitialUrl', () => {
test('throws error if initial route is not set', () => {
expect(() => getInitialUrl()).toThrowError('initialUrl must be set if window.location is unavailable')
})
test('throws error if initial route is not set', () => {
expect(() => getInitialUrl()).toThrowError('initialUrl must be set if window.location is unavailable')
})

0 comments on commit e52fa3d

Please sign in to comment.