CaliStyle / ng-intercom

Angular 7+ Wrapper for Intercom.com
MIT License
54 stars 46 forks source link

Angular Unit Tests #57

Closed marc-wilson closed 5 years ago

marc-wilson commented 6 years ago

Versions

Description

I have previoulsy been using the method recommended on the Intercom site (https://developers.intercom.com/docs/integrate-intercom-in-a-single-page-app) and found to be rather inconsistent/unstable. I ran accross this package and things started to work much more smooth. However, after including it in my Angular app, the majority of my unit tests fail with

Error: StaticInjectorError(DynamicTestModule)[IntercomService -> Intercom]: StaticInjectorError(Platform: core)[IntercomService -> Intercom]: NullInjectorError: No provider for Intercom!

I know that this means I need to add it as a provider to the unit test, but that doesn't seem to work either. Looking through the repo, I do see a tests directory, but it doesn't appear to be testing any of the Intercom module itself. What's the recommended way to make it so I can use the ng-intercom in my application without having all of my unit tests fail. Mock it?

wbhob commented 6 years ago

i didn’t know this was an issue. i can write a mock and build it in so you don’t have to.

marc-wilson commented 6 years ago

Thanks, @wbhob. Let me know if you need an example repo to reproduce the errors.

AntonisFK commented 6 years ago

Upgraded to angular 6 and ng-intercom@6.0.0-beta.3 now my unit test are failing as well. Im getting an window.Intercom is not a function error .

marc-wilson commented 6 years ago

@Antonis: The window.Intercom is not a function error can be worked around. In most places where you're doing window.Intercom, you actually want to do window['Intercom'] (which is the same thing, but it won't piss off the typescript compiler). The other issue with unit tests for this package is going to involve creating a mock class to use in your unit tests and provide that with the ngintercom module. That should fix it. I went back to using the regular intercom code over this since it doesn't seem to be maintained (for what it's worth).

scott-wyatt commented 6 years ago

@mswilson4040 we are always looking for help maintaining! Devs all working together to not have to repeat stuff is why we published this repo. Thank you for your input!

wbhob commented 6 years ago

We are still maintaining this module, but have not had time to make any big changes. It has been relatively stable in our tests and in the community, but nonetheless we are hesitant to publish a full release (not beta- tagged).

wbhob commented 5 years ago

@AntonisFK this is fixed in #67 @mswilson4040 can you share a repo so I can finish up those mocks