Testing private rxMethods in SignalStore #4523
Answered
by
rainerhahnekamp
MotassemJa
asked this question in
Q&A
-
I have a signalStore that has a private method to fetch some data and I call it in the withMethods(store => ({
_fetchData: rxMethod<void>(pipe(
switchMap(() => inject(Service).getData().pipe(
...
))
))
})),
withHooks({
onInit(store) {
store._fetchData()
}
}) How can I unit test the private method with jest? |
Beta Was this translation helpful? Give feedback.
Answered by
rainerhahnekamp
Sep 13, 2024
Replies: 1 comment 4 replies
-
Do you want to test the internals or the behaviour of the store? For the store behaviour, you may spy on the service method, instantiate the store and check for the service call. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Every private method has an impact on the outside/public. In your case, you want to test that the error state is updated.
Provide a test double for
Service
, let it throw an error, and verify that the state got the expected change.