Skip to content

Commit

Permalink
update Injecting fetch docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed Jun 20, 2024
1 parent f536d49 commit e949d97
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,19 +755,24 @@ Output:
To test HTTP requests, you can inject a mock fetch implementation.

```ts
import * as Http from "@effect/platform/HttpClient"
import {
HttpClient,
HttpClientRequest,
HttpClientResponse
} from "@effect/platform"
import { Effect, Layer } from "effect"
import * as assert from "node:assert"

// Mock fetch implementation
const FetchTest = Layer.succeed(Http.client.Fetch, () =>
const FetchTest = Layer.succeed(HttpClient.Fetch, () =>
Promise.resolve(new Response("not found", { status: 404 }))
)

// Program to test
const program = Http.request
.get("https://www.google.com/")
.pipe(Http.client.fetch, Http.response.text)
const program = HttpClientRequest.get("https://www.google.com/").pipe(
HttpClient.fetch,
HttpClientResponse.text
)

// Test
Effect.gen(function* () {
Expand Down

0 comments on commit e949d97

Please sign in to comment.