How to test multiple withLatestFrom store injections in NgRx-Effects?How should I unit test threaded code?How do I test a private function or a class that has private methods, fields or inner classes?How to unit test abstract classes: extend with stubs?Writing unit tests in Python: How do I start?When should I use $provide versus Jasmine Spies in my Angular JS Unit testsTesting ngrx Effects with Jasmine spyRxJs/Ngrx TestSheduler with simulated user input (Jasmine)How to unit test cancellation of in-flight RXJS requestsHow to unit test withLatestFrom in ngrx effectsNGRX Effect withLatestFrom

Is there any reason to concentrate on the Thunderous Smite spell after using its effects?

Is using gradient descent for MIP a good idea?

Bit one of the Intel 8080's Flags register

How to publish superseding results without creating enemies

Some Prime Peerage

Are there any “Third Order” acronyms used in space exploration?

Speedometer as a symbol into awesomebox

How To Make Earth's Oceans as Brackish as Lyr's

I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?

Interaction between Teferi Time Raveler and Enduring Ideal

The Planck constant for mathematicians

Telling my mother that I have anorexia without panicking her

Why does "arimasen" mean "there's no hope"?

Asked to Not Use Transactions and to Use A Workaround to Simulate One

What is the mathematical notation for rounding a given number to the nearest integer?

Can I fix my boots by gluing the soles back on?

How offensive is the French word "femmelette" considered to be?

What organs or modifications would be needed for a life biological creature not to require sleep?

Is there a real-world mythological counterpart to WoW's "kill your gods for power" theme?

What next step can I take in solving this sudoku?

What is the name of this Allen-head furniture fastener?

Can derivatives be defined as anti-integrals?

Make 2019 with single digits

Amortized Loans seem to benefit the bank more than the customer



How to test multiple withLatestFrom store injections in NgRx-Effects?


How should I unit test threaded code?How do I test a private function or a class that has private methods, fields or inner classes?How to unit test abstract classes: extend with stubs?Writing unit tests in Python: How do I start?When should I use $provide versus Jasmine Spies in my Angular JS Unit testsTesting ngrx Effects with Jasmine spyRxJs/Ngrx TestSheduler with simulated user input (Jasmine)How to unit test cancellation of in-flight RXJS requestsHow to unit test withLatestFrom in ngrx effectsNGRX Effect withLatestFrom






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















In our angular webapp we have some NgRx-effects that use different information from different parts of our store. For this we are using the recommended withLatestFrom-approach:



withLatestFrom(
this.store.pipe(select(...)),
this.store.pipe(select(...)),
...
)


While this approach seems to be working fine in production, it feels horrible for unit testing the effects.



For our unit-tests we are currently using jasmine-marbles, jasmine spy-objects and the ngrx MockStore (NgRx 7+). The hard part is to provide the necessary store state, so that the selectors can work properly.



EXAMPLE-EFFECT, for which we do not have a unit-test:



@Effect()
getStammdatenDetails$: Observable<Action> = this.actions$.pipe(
ofType(StammdatenItemDetailActionTypes.REQUEST_DETAILS),
withLatestFrom(
this.store.pipe(select(fromRoot.getMetadata)),
this.store.pipe(select(fromRoot.getCustomerId)),
this.store.pipe(select(fromRoot.getRouterParams))
),
mergeMap(([action, metadata, customerId, params]) =>
*effect logic*
)
);


Maybe someone here can provide more insight or a useful link to a piece of documentation we are missing?



I would really appreciate any help in regards if there is a convenient method to unit tests such effects, or how to refactor those effects to be more "testable" (without moving the problem to another piece of code, which we cannot test afterwards).










share|improve this question
























  • Is this your first steps in testing effects, or you tried some patterns before?

    – Przemyslaw Jan Beigert
    Mar 28 at 15:17











  • We already have setup some tests for our less complex effects but to be honest i'm not quite sure which patterns you are speaking of. Mind sharing a good read?

    – MPreloaded
    Mar 29 at 12:07












  • Sure, give me 1h I'll find something

    – Przemyslaw Jan Beigert
    Mar 29 at 12:09











  • Pls tell me, did you use stuffs like TestBet, Spy, and async unit test in Karma?

    – Przemyslaw Jan Beigert
    Mar 29 at 12:21











  • We set up our TestBed with needed Spys (for used services) and use the fakeAsync()-environment for the tests that need it.

    – MPreloaded
    Mar 29 at 12:24

















1















In our angular webapp we have some NgRx-effects that use different information from different parts of our store. For this we are using the recommended withLatestFrom-approach:



withLatestFrom(
this.store.pipe(select(...)),
this.store.pipe(select(...)),
...
)


While this approach seems to be working fine in production, it feels horrible for unit testing the effects.



For our unit-tests we are currently using jasmine-marbles, jasmine spy-objects and the ngrx MockStore (NgRx 7+). The hard part is to provide the necessary store state, so that the selectors can work properly.



EXAMPLE-EFFECT, for which we do not have a unit-test:



@Effect()
getStammdatenDetails$: Observable<Action> = this.actions$.pipe(
ofType(StammdatenItemDetailActionTypes.REQUEST_DETAILS),
withLatestFrom(
this.store.pipe(select(fromRoot.getMetadata)),
this.store.pipe(select(fromRoot.getCustomerId)),
this.store.pipe(select(fromRoot.getRouterParams))
),
mergeMap(([action, metadata, customerId, params]) =>
*effect logic*
)
);


Maybe someone here can provide more insight or a useful link to a piece of documentation we are missing?



I would really appreciate any help in regards if there is a convenient method to unit tests such effects, or how to refactor those effects to be more "testable" (without moving the problem to another piece of code, which we cannot test afterwards).










share|improve this question
























  • Is this your first steps in testing effects, or you tried some patterns before?

    – Przemyslaw Jan Beigert
    Mar 28 at 15:17











  • We already have setup some tests for our less complex effects but to be honest i'm not quite sure which patterns you are speaking of. Mind sharing a good read?

    – MPreloaded
    Mar 29 at 12:07












  • Sure, give me 1h I'll find something

    – Przemyslaw Jan Beigert
    Mar 29 at 12:09











  • Pls tell me, did you use stuffs like TestBet, Spy, and async unit test in Karma?

    – Przemyslaw Jan Beigert
    Mar 29 at 12:21











  • We set up our TestBed with needed Spys (for used services) and use the fakeAsync()-environment for the tests that need it.

    – MPreloaded
    Mar 29 at 12:24













1












1








1








In our angular webapp we have some NgRx-effects that use different information from different parts of our store. For this we are using the recommended withLatestFrom-approach:



withLatestFrom(
this.store.pipe(select(...)),
this.store.pipe(select(...)),
...
)


While this approach seems to be working fine in production, it feels horrible for unit testing the effects.



For our unit-tests we are currently using jasmine-marbles, jasmine spy-objects and the ngrx MockStore (NgRx 7+). The hard part is to provide the necessary store state, so that the selectors can work properly.



EXAMPLE-EFFECT, for which we do not have a unit-test:



@Effect()
getStammdatenDetails$: Observable<Action> = this.actions$.pipe(
ofType(StammdatenItemDetailActionTypes.REQUEST_DETAILS),
withLatestFrom(
this.store.pipe(select(fromRoot.getMetadata)),
this.store.pipe(select(fromRoot.getCustomerId)),
this.store.pipe(select(fromRoot.getRouterParams))
),
mergeMap(([action, metadata, customerId, params]) =>
*effect logic*
)
);


Maybe someone here can provide more insight or a useful link to a piece of documentation we are missing?



I would really appreciate any help in regards if there is a convenient method to unit tests such effects, or how to refactor those effects to be more "testable" (without moving the problem to another piece of code, which we cannot test afterwards).










share|improve this question














In our angular webapp we have some NgRx-effects that use different information from different parts of our store. For this we are using the recommended withLatestFrom-approach:



withLatestFrom(
this.store.pipe(select(...)),
this.store.pipe(select(...)),
...
)


While this approach seems to be working fine in production, it feels horrible for unit testing the effects.



For our unit-tests we are currently using jasmine-marbles, jasmine spy-objects and the ngrx MockStore (NgRx 7+). The hard part is to provide the necessary store state, so that the selectors can work properly.



EXAMPLE-EFFECT, for which we do not have a unit-test:



@Effect()
getStammdatenDetails$: Observable<Action> = this.actions$.pipe(
ofType(StammdatenItemDetailActionTypes.REQUEST_DETAILS),
withLatestFrom(
this.store.pipe(select(fromRoot.getMetadata)),
this.store.pipe(select(fromRoot.getCustomerId)),
this.store.pipe(select(fromRoot.getRouterParams))
),
mergeMap(([action, metadata, customerId, params]) =>
*effect logic*
)
);


Maybe someone here can provide more insight or a useful link to a piece of documentation we are missing?



I would really appreciate any help in regards if there is a convenient method to unit tests such effects, or how to refactor those effects to be more "testable" (without moving the problem to another piece of code, which we cannot test afterwards).







angular typescript unit-testing testing ngrx






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 28 at 10:53









MPreloadedMPreloaded

84 bronze badges




84 bronze badges















  • Is this your first steps in testing effects, or you tried some patterns before?

    – Przemyslaw Jan Beigert
    Mar 28 at 15:17











  • We already have setup some tests for our less complex effects but to be honest i'm not quite sure which patterns you are speaking of. Mind sharing a good read?

    – MPreloaded
    Mar 29 at 12:07












  • Sure, give me 1h I'll find something

    – Przemyslaw Jan Beigert
    Mar 29 at 12:09











  • Pls tell me, did you use stuffs like TestBet, Spy, and async unit test in Karma?

    – Przemyslaw Jan Beigert
    Mar 29 at 12:21











  • We set up our TestBed with needed Spys (for used services) and use the fakeAsync()-environment for the tests that need it.

    – MPreloaded
    Mar 29 at 12:24

















  • Is this your first steps in testing effects, or you tried some patterns before?

    – Przemyslaw Jan Beigert
    Mar 28 at 15:17











  • We already have setup some tests for our less complex effects but to be honest i'm not quite sure which patterns you are speaking of. Mind sharing a good read?

    – MPreloaded
    Mar 29 at 12:07












  • Sure, give me 1h I'll find something

    – Przemyslaw Jan Beigert
    Mar 29 at 12:09











  • Pls tell me, did you use stuffs like TestBet, Spy, and async unit test in Karma?

    – Przemyslaw Jan Beigert
    Mar 29 at 12:21











  • We set up our TestBed with needed Spys (for used services) and use the fakeAsync()-environment for the tests that need it.

    – MPreloaded
    Mar 29 at 12:24
















Is this your first steps in testing effects, or you tried some patterns before?

– Przemyslaw Jan Beigert
Mar 28 at 15:17





Is this your first steps in testing effects, or you tried some patterns before?

– Przemyslaw Jan Beigert
Mar 28 at 15:17













We already have setup some tests for our less complex effects but to be honest i'm not quite sure which patterns you are speaking of. Mind sharing a good read?

– MPreloaded
Mar 29 at 12:07






We already have setup some tests for our less complex effects but to be honest i'm not quite sure which patterns you are speaking of. Mind sharing a good read?

– MPreloaded
Mar 29 at 12:07














Sure, give me 1h I'll find something

– Przemyslaw Jan Beigert
Mar 29 at 12:09





Sure, give me 1h I'll find something

– Przemyslaw Jan Beigert
Mar 29 at 12:09













Pls tell me, did you use stuffs like TestBet, Spy, and async unit test in Karma?

– Przemyslaw Jan Beigert
Mar 29 at 12:21





Pls tell me, did you use stuffs like TestBet, Spy, and async unit test in Karma?

– Przemyslaw Jan Beigert
Mar 29 at 12:21













We set up our TestBed with needed Spys (for used services) and use the fakeAsync()-environment for the tests that need it.

– MPreloaded
Mar 29 at 12:24





We set up our TestBed with needed Spys (for used services) and use the fakeAsync()-environment for the tests that need it.

– MPreloaded
Mar 29 at 12:24












1 Answer
1






active

oldest

votes


















0
















I suggest to do something like this:



describe('ChapterEffects', () => 
const actions$ = new Subject<any>();
let effects: ChapterEffects;

beforeEach(() =>
TestBed.configureTestingModule(
providers: [
TestedEffects,
provideMockActions(() => actions$),
...otherMocks,
],
);

effects = TestBed.get(ChapterEffects);
);

it('', () =>

);
);


Tested effect:



 @Effect()
fetchData$ = this.actions$.pipe(
ofType<FetchAction>(ActionTypes.FetchAction),
switchMap(( payload ) =>
return this.someService
.get(payload)
.pipe(
map((data) => new LoadAction(data)),
catchError(() => new ErrorAction()),
);
),
);


Thats the sees do your effect and test. You want to test if FetchAction will call get request and load LoadAction when request will finish.



First thing is mock someService in testBet:



const otherMocks = [ provide: SomeService, useValue: get: () => of(42) , ]


now in your test runtime this.someService will be get: () => of(42) }.



Now lets mock FetchAction. In test actions$ is a Subject so you can call actions$.next(new FetchRequest(7)) (7 is a payload).



Then out effect should emit LoadAction with 42, so:



it('', (done) => 
effect.fetchData$.subscribe(action =>
expect(action.payload).toEqual(42);

done()
actions$.next(7);
);





share|improve this answer

























  • While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

    – MPreloaded
    Mar 29 at 13:27












  • It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

    – Przemyslaw Jan Beigert
    Mar 29 at 13:49











  • As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

    – MPreloaded
    Apr 1 at 7:32











  • I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

    – Przemyslaw Jan Beigert
    Apr 1 at 7:40











  • Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

    – MPreloaded
    Apr 1 at 13:37










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395785%2fhow-to-test-multiple-withlatestfrom-store-injections-in-ngrx-effects%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0
















I suggest to do something like this:



describe('ChapterEffects', () => 
const actions$ = new Subject<any>();
let effects: ChapterEffects;

beforeEach(() =>
TestBed.configureTestingModule(
providers: [
TestedEffects,
provideMockActions(() => actions$),
...otherMocks,
],
);

effects = TestBed.get(ChapterEffects);
);

it('', () =>

);
);


Tested effect:



 @Effect()
fetchData$ = this.actions$.pipe(
ofType<FetchAction>(ActionTypes.FetchAction),
switchMap(( payload ) =>
return this.someService
.get(payload)
.pipe(
map((data) => new LoadAction(data)),
catchError(() => new ErrorAction()),
);
),
);


Thats the sees do your effect and test. You want to test if FetchAction will call get request and load LoadAction when request will finish.



First thing is mock someService in testBet:



const otherMocks = [ provide: SomeService, useValue: get: () => of(42) , ]


now in your test runtime this.someService will be get: () => of(42) }.



Now lets mock FetchAction. In test actions$ is a Subject so you can call actions$.next(new FetchRequest(7)) (7 is a payload).



Then out effect should emit LoadAction with 42, so:



it('', (done) => 
effect.fetchData$.subscribe(action =>
expect(action.payload).toEqual(42);

done()
actions$.next(7);
);





share|improve this answer

























  • While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

    – MPreloaded
    Mar 29 at 13:27












  • It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

    – Przemyslaw Jan Beigert
    Mar 29 at 13:49











  • As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

    – MPreloaded
    Apr 1 at 7:32











  • I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

    – Przemyslaw Jan Beigert
    Apr 1 at 7:40











  • Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

    – MPreloaded
    Apr 1 at 13:37















0
















I suggest to do something like this:



describe('ChapterEffects', () => 
const actions$ = new Subject<any>();
let effects: ChapterEffects;

beforeEach(() =>
TestBed.configureTestingModule(
providers: [
TestedEffects,
provideMockActions(() => actions$),
...otherMocks,
],
);

effects = TestBed.get(ChapterEffects);
);

it('', () =>

);
);


Tested effect:



 @Effect()
fetchData$ = this.actions$.pipe(
ofType<FetchAction>(ActionTypes.FetchAction),
switchMap(( payload ) =>
return this.someService
.get(payload)
.pipe(
map((data) => new LoadAction(data)),
catchError(() => new ErrorAction()),
);
),
);


Thats the sees do your effect and test. You want to test if FetchAction will call get request and load LoadAction when request will finish.



First thing is mock someService in testBet:



const otherMocks = [ provide: SomeService, useValue: get: () => of(42) , ]


now in your test runtime this.someService will be get: () => of(42) }.



Now lets mock FetchAction. In test actions$ is a Subject so you can call actions$.next(new FetchRequest(7)) (7 is a payload).



Then out effect should emit LoadAction with 42, so:



it('', (done) => 
effect.fetchData$.subscribe(action =>
expect(action.payload).toEqual(42);

done()
actions$.next(7);
);





share|improve this answer

























  • While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

    – MPreloaded
    Mar 29 at 13:27












  • It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

    – Przemyslaw Jan Beigert
    Mar 29 at 13:49











  • As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

    – MPreloaded
    Apr 1 at 7:32











  • I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

    – Przemyslaw Jan Beigert
    Apr 1 at 7:40











  • Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

    – MPreloaded
    Apr 1 at 13:37













0














0










0









I suggest to do something like this:



describe('ChapterEffects', () => 
const actions$ = new Subject<any>();
let effects: ChapterEffects;

beforeEach(() =>
TestBed.configureTestingModule(
providers: [
TestedEffects,
provideMockActions(() => actions$),
...otherMocks,
],
);

effects = TestBed.get(ChapterEffects);
);

it('', () =>

);
);


Tested effect:



 @Effect()
fetchData$ = this.actions$.pipe(
ofType<FetchAction>(ActionTypes.FetchAction),
switchMap(( payload ) =>
return this.someService
.get(payload)
.pipe(
map((data) => new LoadAction(data)),
catchError(() => new ErrorAction()),
);
),
);


Thats the sees do your effect and test. You want to test if FetchAction will call get request and load LoadAction when request will finish.



First thing is mock someService in testBet:



const otherMocks = [ provide: SomeService, useValue: get: () => of(42) , ]


now in your test runtime this.someService will be get: () => of(42) }.



Now lets mock FetchAction. In test actions$ is a Subject so you can call actions$.next(new FetchRequest(7)) (7 is a payload).



Then out effect should emit LoadAction with 42, so:



it('', (done) => 
effect.fetchData$.subscribe(action =>
expect(action.payload).toEqual(42);

done()
actions$.next(7);
);





share|improve this answer













I suggest to do something like this:



describe('ChapterEffects', () => 
const actions$ = new Subject<any>();
let effects: ChapterEffects;

beforeEach(() =>
TestBed.configureTestingModule(
providers: [
TestedEffects,
provideMockActions(() => actions$),
...otherMocks,
],
);

effects = TestBed.get(ChapterEffects);
);

it('', () =>

);
);


Tested effect:



 @Effect()
fetchData$ = this.actions$.pipe(
ofType<FetchAction>(ActionTypes.FetchAction),
switchMap(( payload ) =>
return this.someService
.get(payload)
.pipe(
map((data) => new LoadAction(data)),
catchError(() => new ErrorAction()),
);
),
);


Thats the sees do your effect and test. You want to test if FetchAction will call get request and load LoadAction when request will finish.



First thing is mock someService in testBet:



const otherMocks = [ provide: SomeService, useValue: get: () => of(42) , ]


now in your test runtime this.someService will be get: () => of(42) }.



Now lets mock FetchAction. In test actions$ is a Subject so you can call actions$.next(new FetchRequest(7)) (7 is a payload).



Then out effect should emit LoadAction with 42, so:



it('', (done) => 
effect.fetchData$.subscribe(action =>
expect(action.payload).toEqual(42);

done()
actions$.next(7);
);






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 29 at 13:18









Przemyslaw Jan BeigertPrzemyslaw Jan Beigert

1,1091 gold badge6 silver badges12 bronze badges




1,1091 gold badge6 silver badges12 bronze badges















  • While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

    – MPreloaded
    Mar 29 at 13:27












  • It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

    – Przemyslaw Jan Beigert
    Mar 29 at 13:49











  • As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

    – MPreloaded
    Apr 1 at 7:32











  • I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

    – Przemyslaw Jan Beigert
    Apr 1 at 7:40











  • Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

    – MPreloaded
    Apr 1 at 13:37

















  • While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

    – MPreloaded
    Mar 29 at 13:27












  • It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

    – Przemyslaw Jan Beigert
    Mar 29 at 13:49











  • As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

    – MPreloaded
    Apr 1 at 7:32











  • I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

    – Przemyslaw Jan Beigert
    Apr 1 at 7:40











  • Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

    – MPreloaded
    Apr 1 at 13:37
















While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

– MPreloaded
Mar 29 at 13:27






While this is a good summary for how to test ngrx effects in general, the part i am struggling with in my question is, how to convienently test effects that use parts of the store (hence withLatestFrom(this.store.pipe(select(...)))). One way would be to completely mock the store but because our store-structure is already quite big, i feel that there has to be a more convenient solution.

– MPreloaded
Mar 29 at 13:27














It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

– Przemyslaw Jan Beigert
Mar 29 at 13:49





It will be pretty much the same case as in SomeService. this.store is taken from DI so you can easily mock it by provide: Store, useValue: new BehaviorSubject() and with BehaviorSubject you can push current mocked state.

– Przemyslaw Jan Beigert
Mar 29 at 13:49













As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

– MPreloaded
Apr 1 at 7:32





As stated, i already knew about this option (but i would prefer to use the MockStore from ngrx). Our store structure is nested deeply, so that it feels like a big overhead to build such a store for different testcases. But maybe there isn't another way currently... I will accept this answer thanks for your help its much appreciated!

– MPreloaded
Apr 1 at 7:32













I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

– Przemyslaw Jan Beigert
Apr 1 at 7:40





I know that, hoverer i didn't want to recommend you patterns witch i didn't check in my applications. For me it's not perfect because required a lot of code, but it works well.

– Przemyslaw Jan Beigert
Apr 1 at 7:40













Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

– MPreloaded
Apr 1 at 13:37





Out of pure interest: Could you name those patterns you can not recommend? I would like to read up on them!

– MPreloaded
Apr 1 at 13:37








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395785%2fhow-to-test-multiple-withlatestfrom-store-injections-in-ngrx-effects%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현