@goodie-ts/testing 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +60 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # @goodie-ts/testing
2
+
3
+ Test utilities for [goodie-ts](https://github.com/GOOD-Code-ApS/goodie) with bean overrides and mock definitions.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add -D @goodie-ts/testing
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ Provides `TestContext` for creating isolated `ApplicationContext` instances with bean overrides — perfect for unit and integration tests.
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { TestContext } from '@goodie-ts/testing';
19
+ import { definitions } from './AppContext.generated.js';
20
+
21
+ const ctx = await TestContext.from(definitions)
22
+ .override(UserRepoToken).withValue(new MockUserRepo())
23
+ .override(LoggerToken).withFactory(() => new TestLogger())
24
+ .build();
25
+
26
+ const service = ctx.get(UserService);
27
+ ```
28
+
29
+ ## API
30
+
31
+ ### TestContext.from(definitions | context)
32
+
33
+ Creates a `TestContextBuilder` from bean definitions or an existing context.
34
+
35
+ - `.override(token).withValue(instance)` — replace with a fixed value
36
+ - `.override(token).with(MockClass)` — replace with a zero-dep class
37
+ - `.override(token).withFactory(() => ...)` — replace with a custom factory
38
+ - `.mock(MockClass, ...)` — register `@MockDefinition` classes
39
+ - `.build()` — returns a `Promise<ApplicationContext>`
40
+
41
+ ### @MockDefinition(target)
42
+
43
+ Decorator that marks a class as a mock replacement for a specific token:
44
+
45
+ ```typescript
46
+ import { MockDefinition } from '@goodie-ts/testing';
47
+
48
+ @MockDefinition(UserRepoToken)
49
+ class MockUserRepo extends UserRepository {
50
+ findAll() { return [{ id: 'mock', name: 'Test User' }]; }
51
+ }
52
+
53
+ const ctx = await TestContext.from(definitions)
54
+ .mock(MockUserRepo)
55
+ .build();
56
+ ```
57
+
58
+ ## License
59
+
60
+ [MIT](https://github.com/GOOD-Code-ApS/goodie/blob/main/LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodie-ts/testing",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Test utilities for goodie-ts with bean overrides and mock definitions",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@goodie-ts/core": "0.1.0"
24
+ "@goodie-ts/core": "0.1.1"
25
25
  },
26
26
  "files": [
27
27
  "dist"