Skip to content

Commit 2964e2b

Browse files
timdeschryverbrandonroberts
authored andcommitted
feat(store): cleanup selector after a test
1 parent 88ebdde commit 2964e2b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

modules/store/testing/src/mock_store.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Inject, Injectable } from '@angular/core';
2+
import { TestBed } from '@angular/core/testing';
23
import { Observable, BehaviorSubject } from 'rxjs';
34
import {
45
Action,
@@ -14,6 +15,17 @@ import { MockState } from './mock_state';
1415
import { MockSelector } from './mock_selector';
1516
import { MOCK_SELECTORS } from './tokens';
1617

18+
if (typeof afterEach === 'function') {
19+
afterEach(() => {
20+
try {
21+
const store = TestBed.get(Store) as MockStore<any>;
22+
if (store && 'resetSelectors' in store) {
23+
store.resetSelectors();
24+
}
25+
} catch {}
26+
});
27+
}
28+
1729
@Injectable()
1830
export class MockStore<T> extends Store<T> {
1931
static selectors = new Map<

0 commit comments

Comments
 (0)