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
In a zoneless environment, `fixture.detectChanges()` is used for immediate synchronous rendering. For signal updates and other async logic, use `await fixture.whenStable()` before DOM assertions so the scheduler can finish.
447
+
448
+
```typescript
449
+
it('should update UI after signal change', async () => {
@@ -854,7 +894,7 @@ This project strictly enforces 90%+ test coverage through GitHub Actions CI.
854
894
855
895
## 18. Best Practices
856
896
857
-
1.**Always use `provideOSFCore()`** — never import `OSFTestingModule` directly in new tests.
897
+
1.**Always use `provideOSFCore()`**.
858
898
2.**Always use `provideMockStore()`** — never mock `component.actions` via `Object.defineProperty`.
859
899
3.**Always pass explicit mocks to `MockProvider`** when you need `jest.fn()` assertions. Bare `MockProvider(Service)` creates ng-mocks stubs.
860
900
4.**Check `@testing/` before creating inline mocks** — builders and factories almost certainly exist.
@@ -863,13 +903,12 @@ This project strictly enforces 90%+ test coverage through GitHub Actions CI.
863
903
7.**Use `(store.dispatch as jest.Mock).mockClear()`** when `ngOnInit` dispatches and you need isolated per-test assertions.
864
904
8.**Use `WritableSignal` for dynamic state** — pass `signal()` values to `provideMockStore` when tests need to mutate state mid-test.
865
905
9.**Use `Subject` for dialog `onClose`** — gives explicit control over dialog result timing. Use `provideDynamicDialogRefMock()` where applicable.
866
-
10.**Use `fakeAsync` + `tick`** for debounced operations — specify the exact debounce duration.
906
+
10.**Use Jest fake timers** for debounced operations — `jest.useFakeTimers()`, `jest.advanceTimersByTime(ms)`, and `jest.useRealTimers()`.
867
907
11.**Use `fixture.componentRef.setInput()`** for signal inputs — never direct property assignment.
868
-
12.**Use `ngMocks.faster()`** when all tests in a file share identical `TestBed` config — reuses the compiled module for speed. Do not use if any test requires a different config: shared state will cause subtle test pollution.
14.**Test both positive and negative paths** — confirm an action fires AND confirm it does not fire when conditions are not met.
871
-
15.**Only use `@testing/data` fixtures in HTTP flushes** — never hardcode response values inline in service or state tests.
872
-
16.**Each test should highlight the most critical aspect of the code** — if a test fails during a refactor, it should clearly signal that a core feature was impacted.
13.**Test both positive and negative paths** — confirm an action fires AND confirm it does not fire when conditions are not met.
910
+
14.**Only use `@testing/data` fixtures in HTTP flushes** — never hardcode response values inline in service or state tests.
911
+
15.**Each test should highlight the most critical aspect of the code** — if a test fails during a refactor, it should clearly signal that a core feature was impacted.
0 commit comments