@dumbql/testing 0.0.1 → 0.0.2-alpha.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.
- package/README.md +49 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# @dumbql/testing
|
|
2
|
+
|
|
3
|
+
Mock GraphQL backend for unit testing DumbQL queries and mutations.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dumbql/testing
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { provideDumbqlTesting, MockGraphqlService } from '@dumbql/testing';
|
|
15
|
+
|
|
16
|
+
TestBed.configureTestingModule({
|
|
17
|
+
providers: [provideDumbqlTesting()],
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('mocks a query', () => {
|
|
21
|
+
const mock = TestBed.inject(MockGraphqlService);
|
|
22
|
+
mock.when(
|
|
23
|
+
gql`query Todos { todos { id } }`,
|
|
24
|
+
{ data: { todos: [{ id: '1' }] } },
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const graphql = TestBed.inject(GraphqlService);
|
|
28
|
+
graphql.query(gql`query Todos { todos { id } }`).subscribe(result => {
|
|
29
|
+
expect(result.status).toBe('success');
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## API
|
|
35
|
+
|
|
36
|
+
| Export | Description |
|
|
37
|
+
|--------|-------------|
|
|
38
|
+
| `MockGraphqlService` | FIFO mock — `when(request, result)` registers responses |
|
|
39
|
+
| `provideDumbqlTesting()` | Provider array for `TestBed` |
|
|
40
|
+
| `MockedRequest` | `{ query: string; variables?: Record<string, unknown> }` |
|
|
41
|
+
| `MockedResponse` | `{ data?: T; errors?: { message: string }[] }` |
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
Responses are consumed FIFO. If no mock is registered for a request, the service returns `{ status: 'error', error: 'No mock response configured' }`.
|
|
46
|
+
|
|
47
|
+
## Dependencies
|
|
48
|
+
|
|
49
|
+
`@angular/core`, `@dumbql/core`, `rxjs`
|