Skip to content

Commit

Permalink
fix: Drastically reduce the time for each iteration of running tests …
Browse files Browse the repository at this point in the history
…from >60s to ~4s (x17!)

Drastically reduce the time for each iteration of running tests from >60s to ~4s (x17!)
  • Loading branch information
ReiiYuki authored May 16, 2023
2 parents 74de705 + b7947f6 commit 302a256
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ describe('getCurrentLocationWithTimeout()', () => {
longitude: 45.3
}
}

const MOCK_REJECT_RESPONSE = new Error('reject')

const mockGetCurrentPosition = jest.fn()

beforeAll(() => {
jest.useFakeTimers()
Object.defineProperty(window, 'navigator', {
value: {
geolocation: {
Expand All @@ -25,6 +24,7 @@ describe('getCurrentLocationWithTimeout()', () => {

afterEach(() => {
mockGetCurrentPosition.mockClear()
jest.clearAllTimers()
})

describe('geolocation resolve after timeout', () => {
Expand All @@ -33,6 +33,7 @@ describe('getCurrentLocationWithTimeout()', () => {
setTimeout(() => {
resolve(MOCK_RESPONSE)
}, 50000)
jest.runAllTimers()
})
})

Expand All @@ -51,6 +52,7 @@ describe('getCurrentLocationWithTimeout()', () => {
setTimeout(() => {
reject(MOCK_REJECT_RESPONSE)
}, 50000)
jest.runAllTimers()
})
})

Expand All @@ -69,6 +71,7 @@ describe('getCurrentLocationWithTimeout()', () => {
setTimeout(() => {
resolve(MOCK_RESPONSE)
}, 500)
jest.runAllTimers()
})
})

Expand All @@ -87,6 +90,7 @@ describe('getCurrentLocationWithTimeout()', () => {
setTimeout(() => {
reject(MOCK_REJECT_RESPONSE)
}, 500)
jest.runAllTimers()
})
})

Expand Down

0 comments on commit 302a256

Please sign in to comment.