Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e2fcc4b

Browse files
committed
chore(state): add test cases for rxEffects options
1 parent 56d8c34 commit e2fcc4b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

libs/state/effects/src/lib/rx-effects.spec.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, EnvironmentInjector } from '@angular/core';
22
import { TestBed } from '@angular/core/testing';
33
import { jestMatcher } from '@test-helpers/rx-angular';
44
import { Observable, of, Subject, tap, timer } from 'rxjs';
@@ -104,6 +104,24 @@ describe(rxEffects, () => {
104104
expect(spyInternalOnCleanup).toHaveBeenCalled();
105105
expect(spyOnCleanup).toHaveBeenCalled();
106106
});
107+
108+
describe('without injection context', () => {
109+
it('should throw when invoked without injection context', () => {
110+
const { rxEffects } = setUpWithoutInjectionContext();
111+
expect(() => rxEffects(() => {}, {})).toThrow(
112+
/rxEffects\(\) can only be used within an injection context/,
113+
);
114+
});
115+
116+
it('should be able to use a custom Injector', () => {
117+
const { rxEffects } = setUpWithoutInjectionContext();
118+
119+
const envInjector = TestBed.inject(EnvironmentInjector);
120+
121+
const effects = rxEffects(() => {}, { injector: envInjector });
122+
expect(effects).toBeDefined();
123+
});
124+
});
107125
});
108126

109127
function setupComponent(setupFn?: RxEffectsSetupFn) {
@@ -123,3 +141,12 @@ function setupComponent(setupFn?: RxEffectsSetupFn) {
123141
component: fixture.componentInstance,
124142
};
125143
}
144+
145+
function setUpWithoutInjectionContext() {
146+
return {
147+
rxEffects(...args: Parameters<typeof rxEffects>) {
148+
const effects = rxEffects(...args);
149+
return effects;
150+
},
151+
};
152+
}

0 commit comments

Comments
 (0)