Skip to content

Commit

Permalink
chore: adjust test case failure
Browse files Browse the repository at this point in the history
chore: lint
  • Loading branch information
chrisbbreuer committed Jan 17, 2025
1 parent 05dcd18 commit 2b6adca
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/dnsx.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeAll, describe, expect, it, mock } from 'bun:test'
import { afterAll, beforeAll, describe, expect, it, mock } from 'bun:test'
import { Buffer } from 'node:buffer'
import { buildQuery, DnsClient, DnsDecoder, DnsFlags, parseResponse } from '../src'
import { TransportType } from '../src/transport'
Expand Down Expand Up @@ -195,19 +195,28 @@ describe('DnsClient', () => {
})

it('should handle network errors', async () => {
mock.module('./src/transport', () => ({
// Mock the transport to always fail
const originalModule = await import('../src/transport')
const mockTransport = {
...originalModule,
createTransport: () => ({
query: async () => { throw new Error('Network error') },
query: () => Promise.reject(new Error('Network error')),
}),
TransportType,
}))
}

mock.module('../src/transport', () => mockTransport)

const client = new DnsClient({
domains: ['example.com'],
type: 'A',
})

await expect(client.query()).rejects.toThrow()
expect(client.query()).rejects.toThrow('DNS query failed: Network error')
})

// Restore original transport after test
afterAll(() => {
mock.restore()
})
})

Expand Down

0 comments on commit 2b6adca

Please sign in to comment.