-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.test.ts
More file actions
33 lines (27 loc) · 976 Bytes
/
index.test.ts
File metadata and controls
33 lines (27 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { ConfigProvider, Effect, Layer, ManagedRuntime } from "effect";
import { afterAll, afterEach, beforeAll, expect, it } from "vitest";
import { server } from "../test/node";
import { PokeApi } from "./PokeApi";
beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
const TestConfigProvider = ConfigProvider.fromMap(
new Map([["BASE_URL", "http://localhost:3000"]])
);
const ConfigProviderLayer = Layer.setConfigProvider(TestConfigProvider);
const MainLayer = PokeApi.Default.pipe(Layer.provide(ConfigProviderLayer));
const TestingRuntime = ManagedRuntime.make(MainLayer);
const program = Effect.gen(function* () {
const pokeApi = yield* PokeApi;
return yield* pokeApi.getPokemon;
});
it("returns a valid pokemon", async () => {
const response = await TestingRuntime.runPromise(program);
expect(response).toEqual({
id: 1,
height: 10,
weight: 10,
order: 1,
name: "myname",
});
});