Skip to content

Commit

Permalink
test: partially apply Rabbit suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiTimesChi committed Nov 7, 2024
1 parent 08d6bfd commit 2c363dc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/sdk-router/src/rfq/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,28 @@ describe('getAllQuotes', () => {
})

describe('Returns an empty array', () => {
beforeAll(() => {
console.error = jest.fn()
beforeEach(() => {
jest.spyOn(console, 'error').mockImplementation(() => {
// Do nothing
})
})

afterEach(() => {
jest.restoreAllMocks()
})

it('when the response is not ok', async () => {
fetchMock.mockResponseOnce(JSON.stringify(quotesAPI), { status: 500 })
const result = await getAllQuotes()
expect(result).toEqual([])
expect(console.error).toHaveBeenCalled()
})

it('when fetch throws an error', async () => {
fetchMock.mockRejectOnce(new Error('Error fetching quotes'))
const result = await getAllQuotes()
expect(result).toEqual([])
expect(console.error).toHaveBeenCalled()
})

it('when the response takes too long to return', async () => {
Expand All @@ -98,6 +106,7 @@ describe('getAllQuotes', () => {
)
const result = await getAllQuotes()
expect(result).toEqual([])
expect(console.error).toHaveBeenCalled()
})
})
})

0 comments on commit 2c363dc

Please sign in to comment.