Unit testing in Angular with ng-lottie element
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Other... Please describe:
My setup is trivial angular unit testing with karma and jasmine.
What is this request about?
@arturovt Thank you for developing this library. It is really great and easy to work with. Excuse me if my more of a support request does not belong here and should be deleted.
One issue I am facing in my current setup is when I test Lottie in a *ngIf directive. In this case, when the animation should be displayed but really quickly I change the binding of the *ngIf to be false I have the LottieEventFacade calling dispose method which calls destroy on an animatiionItem of null `private dispose(): void { if (isPlatformServer(this.platformId)) { return; }
// destroy() will remove all events listeners
this.animationItem!.destroy(); // in here this.animationItem is not shown.
this.animationItem = null;
}` And later in time the loadAnimation method is triggered.
Since I am not proficient with testing and what to mock in this case, I currently have added CUSTOM_ELEMENTS_SCHEMA to the tests so I can go around the issue. Another way around for me was to Provide the PLATFORM_ID token as “server” because then the destroy is not called.
All in all my question is how is the best approach to test this scenario:
- Lottie directive starts
- The ng-lottie element is destroyed before it has loaded and initialized the animationItem
- An error is thrown that cannot call destroy() of null
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Related StackOverflow Question
I have published
5.3.1. Could you check it up?@arturovt
You are awesome 🥇 Thank you for fixing it up! It does work like a charm now.