Skip to content

Commit

Permalink
Remove the networkError option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowno committed Dec 1, 2023
1 parent 28f219b commit 164b024
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 23 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,6 @@ Type: `integer`

Delays the response by the given number of milliseconds. Useful for testing timeouts.

###### networkError

Type: `boolean`

Simulates a `ECONNRESET` error by abruptly ending the connection. Useful for testing network error handling and retries.

#### verify()

Utility function for making sure all the requests were stubbed. It throws an exception if some of the requests weren't stubbed or if some of the stubs weren't used. Useful for calling in the `afterEach` test hook to make sure everything ran as expected.
Expand Down
1 change: 0 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface AddStubOptions {
headers?: Headers
body?: Body | AddStubOptionsBodyCallback
delay?: number
networkError?: boolean
}

export declare class HttpStub {
Expand Down
6 changes: 0 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const stubSchema = joi
headers: joi.object().pattern(/.*/, joi.string()),
body: joi.any(),
delay: joi.number().min(0).integer(),
networkError: joi.bool(),
})
.default()

Expand Down Expand Up @@ -216,11 +215,6 @@ class HttpStub {
await sleep(stub.delay)
}

if (stub.networkError) {
req.destroy()
return
}

if (stub.headers) {
for (const name of Object.keys(stub.headers)) {
const value = stub.headers[name]
Expand Down
10 changes: 0 additions & 10 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ test('can delay a response', async (t) => {
t.true(duration >= 1000)
})

test('can simulate a network error', async (t) => {
const httpStub = await createHttpStub()
t.context.httpStub = httpStub

httpStub.addStub({ networkError: true })

const error = await t.throwsAsync(got(httpStub.url, { retry: 0 }))
t.is(error.code, 'ECONNRESET')
})

test('supports json request bodies', async (t) => {
const httpStub = await createHttpStub()
t.context.httpStub = httpStub
Expand Down

0 comments on commit 164b024

Please sign in to comment.