You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns `FactoryProvider`. Each time a component invokes the factory function, a fresh ref is created, registered in the bus under `key`, and `initialBehavior` is applied — simulating the full request lifecycle on every mount.
355
382
356
383
The optional `meta` argument is a `MockResourceMeta` object. When provided, the DevTools panel uses it to look up response schemas and pre-populate the Respond tab's schema display. Generated `.mock.ts` files embed this automatically — you only need to pass it manually when using `provideMockResource()` directly.
357
384
385
+
The optional `options` argument is a `MockProviderOptions` object — see below.
386
+
358
387
`initialBehavior` controls how the mock behaves on each invocation:
359
388
360
389
| Shape | Effect |
@@ -365,6 +394,33 @@ The optional `meta` argument is a `MockResourceMeta` object. When provided, the
365
394
|`{ error: unknown }`| Fails immediately |
366
395
|`{ error: unknown, delay: ms }`| Loading for `ms` ms, then fails |
367
396
397
+
### `MockProviderOptions`
398
+
399
+
Passed as the fifth argument to `provideMockResource()` and as the second argument to generated `provide{Operation}Mock()` wrappers.
400
+
401
+
```typescript
402
+
interfaceMockProviderOptions {
403
+
keyDiscriminator?: () =>string;
404
+
}
405
+
```
406
+
407
+
**`keyDiscriminator`** — called inside the factory injection context to produce a suffix appended to the bus key as `key:suffix`. Use this when the same token appears in multiple component instances simultaneously (e.g. list rows) so each instance is independently addressable:
408
+
409
+
```typescript
410
+
// List row component — each instance registers under a unique key
Without `keyDiscriminator`, the last-mounted instance overwrites earlier registrations under the same key.
421
+
422
+
---
423
+
368
424
### `injectMockResource<T>(key)`
369
425
370
426
Must be called inside an injection context (e.g. `TestBed.runInInjectionContext`) and after the component has rendered — the ref is registered when the component first invokes the factory function, not at DI setup time. Returns `MockResourceRef<T>`.
@@ -428,18 +484,19 @@ Creates a standalone ref without the bus — useful for Storybook decorators, cu
428
484
|`error: Signal<unknown>`| Current error, if any |
429
485
|`isLoading: Signal<boolean>`|`true` while status is `'loading'` or `'reloading'`|
430
486
|`progress: Signal<MockProgress \| undefined>`| Current transfer progress, if active |
487
+
|`requestCount: Signal<number>`| Total factory invocations (increments on mount, reactive param change, and `reload()`) |
431
488
|`hasValue(): boolean`|`true` when value is set |
432
489
|`resolve(value: T)`| Set value, clear error and progress → `'resolved'`|
433
490
|`resolveAfter(ms, value)`| Set loading immediately, resolve after delay |
434
491
|`setLoading()`| Clear error → `'loading'`|
435
492
|`fail(error)`| Set error → `'error'` (progress preserved) |
436
493
|`reset()`| Clear all including progress → `'idle'`|
494
+
|`reload()`| Keep value, clear error → `'reloading'`; fires request event; returns `true`. Returns `false` if status is not `'resolved'` or `'local'`|
437
495
|`setProgress(type, loaded, total?)`| Set progress and status → `'loading'`|
438
496
|`simulateProgress(type, totalBytes, durationMs, finalValue, steps?)`| Animate incremental progress over `durationMs` ms then resolve |
439
497
|`set(value)`| Local mutation → `'local'` (ResourceRef interface) |
440
498
|`update(fn)`| Local update → `'local'` (ResourceRef interface) |
441
499
|`onRequest(cb)`| Subscribe to factory invocations; returns unsubscribe fn |
|`simulateProgress(type, totalBytes, durationMs, finalValue, steps?)`| Animate progress then resolve — emits `loading`, one `progress` event per step, then `resolve`|
0 commit comments