ngrx-run
Version:
Return side-effects as data from your NgRx reducers
52 lines (48 loc) • 1.59 kB
JavaScript
import { __awaiter } from 'tslib';
import { Store } from '@ngrx/store';
import { TestBed } from '@angular/core/testing';
import { EffectStoreModule } from 'ngrx-run';
import { first } from 'rxjs/operators';
function simulate(reducer, actions, config) {
return __awaiter(this, void 0, void 0, function* () {
jest.useFakeTimers();
TestBed.configureTestingModule({
imports: [EffectStoreModule.forRoot({ feature: reducer })],
providers: config === null || config === void 0 ? void 0 : config.providers
});
const store = TestBed.inject(Store);
for (const action of actions) {
store.dispatch(action);
jest.runOnlyPendingTimers();
}
jest.useRealTimers();
return yield firstValueFrom(store.select((state) => state.feature));
});
}
const testing = {};
expect.extend({
toHaveEffect(received, expected) {
const pass = received.effects.includes(expected);
if (pass) {
return {
pass: true,
message: () => `expected reducer to have effect ${expected.type}`
};
}
else {
return {
pass: false,
message: () => `expected reducer to have effect ${expected.type}`
};
}
}
});
/* Util */
function firstValueFrom(obs$) {
return obs$.pipe(first()).toPromise();
}
/**
* Generated bundle index. Do not edit.
*/
export { simulate, testing };
//# sourceMappingURL=ngrx-run-testing.js.map