briebug / ngrx-auto-entity

NgRx Auto-Entity: Simplifying Reactive State
https://briebug.gitbook.io/ngrx-auto-entity/
Other
66 stars 12 forks source link

Unable to unit test facade in feature module #223

Closed ZsZs closed 1 year ago

ZsZs commented 2 years ago

Hi,

I'm a big fan of this library, I'm using it since 2 years ago. Now I want to strengthen the test coverage, with Jest tests. While doing this, I stuck with the problem, to test entity facades in feature libraries. To eliminate other, maybe distracting features, and configurations, I created a dedicated repo, to demonstrate my problem: https://github.com/ZsZs/auto-entity-test

In this simple application, I defined @Entity class TestEntity in both, AppModule and SharedAutoEntityModule. First of all, the application, including the creation of facades works. You can verify by: https://github.com/ZsZs/auto-entity-test/blob/main/package.json#L8 My unit test for TestEntityFacade also works in AppModule: https://github.com/ZsZs/auto-entity-test/blob/main/apps/auto-entity-test/src/app/auto-entity/test-entity-facade.spec.ts

On the other hand in the feature module, the almost same test https://github.com/ZsZs/auto-entity-test/blob/main/libs/shared/auto-entity/src/lib/auto-entity/test-entity-facade.spec.ts doesn't work. It tried to mock the service, but also without mocking anything. The result is always the same. The facade.all$ does not retrieves any entities: https://github.com/ZsZs/auto-entity-test/blob/main/libs/shared/auto-entity/src/lib/auto-entity/test-entity-facade.spec.ts#L64

I'm stuck. What I oversee, what I'm doing wrong?

jrista commented 1 year ago

Hi @ZsZs. Thanks for the support! We appreciate it! Regarding the unit testing issue, give me a bit of time to investigate your repo and I'll see if I can help you resolve the issue.

ZsZs commented 1 year ago

Thank @jrista , for your response. I spent quite a lot of time trying different unit test configurations for the feature module, without any success. I'm really curious, about what I oversee.

jrista commented 1 year ago

@ZsZs I've been poking around with it...its definitely strange. I think it may have to do with some wiring up of all the stuff involved in an Auto-Entity "entity state"... It does not appear as though the entity service is actually kicking off the auto-entity effects. I'm having trouble actually debugging auto-entity source code...not sure if this is because of Ivy or what, but the sourcemaps seem to be out of alignment. I am going to try to recreate your test scenario in a new test project within ngrx-auto-entity's repo itself, and see if I can debug through the code to figure out what's happening. I'll probably push that to its own branch, and I'll share the branch name here in the event you want to get in there and poke around yourself.

ZsZs commented 1 year ago

@jrista, thank you. Yes, I'm interested.

jrista commented 1 year ago

@ZsZs I just wanted to let you know I haven't lost sight of this. I've had a wildly busy month, had a car stolen, and a number of other things happen. I'm still trying to recover from the car (and wallet) theft here. I am hoping to get back into this within the next week here, so long as nothing else goes awry.

ZsZs commented 1 year ago

Hi, I figured out, the problem was with the test setup. If I use MockBuilder then everything works as expected. See: https://github.com/ZsZs/auto-entity-test/commit/cd35b877f81e801f70ed61666639b1715f3c7351#diff-da460504d6200d594f2c92c9d2f874562c4199bc30b22bc1c746dceca152ba04

Cheers, Zsolt