mercredi 18 novembre 2015

Widget is causing typeError in Karma + Jasmine test

My goal is to set up unit testing for a legacy MEAN stack codebase to start using TDD and I'm new to setting up testing configuration. Our app uses an Amplitude widget for some of our user stats. It's loaded via SCRIPT tag into the HEAD of our index.html and initiated in a service. We've been using amplitude for more than a month without issues, but now when I try to run karma, unless I disable the service, I get this error that runs for every file I load that uses the service:

18 11 2015 10:06:56.265:INFO [karma]: Karma v0.13.15 server started at http://localhost:8080/
18 11 2015 10:06:56.272:INFO [launcher]: Starting browser PhantomJS
18 11 2015 10:06:57.012:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket 5YQAeA9e46_zw-ZyAAAA with id 72539271
PhantomJS 1.9.8 (Mac OS X 0.0.0) LOG: 'WARNING: Tried to load angular more than once.'

ERROR: 'Error: Raven has already been configured'
PhantomJS 1.9.8 (Mac OS X 0.0.0) Directive: elastic should make hidden element visible FAILED
TypeError: 'undefined' is not an object (evaluating '$window.amplitude.log = log')
    at Amplitude  (/path/to/app/client/app/services/amplitude/amplitude.service.js:9)

If I have the amplitude initiation service disabled I get this:

18 11 2015 09:47:09.612:INFO [karma]: Karma v0.13.15 server started at http://localhost:8080/
18 11 2015 09:47:09.619:INFO [launcher]: Starting browser PhantomJS
18 11 2015 09:47:10.346:INFO [PhantomJS 1.9.8 (Mac OS X 0.0.0)]: Connected on socket ugfCOHqeeav9hC-sAAAA with id 52254080
PhantomJS 1.9.8 (Mac OS X 0.0.0) LOG: 'WARNING: Tried to load angular more than once.'

ERROR: 'Error: Raven has already been configured'

As far as I know the Raven configuration error and load angular more than once error are entirely separate issues. My instinct is that this has to do with asynchronous loading of the widget, leaving it 'undefined' when the tests run. I haven't been able to find any helpful documents on how to fix this issue. Any help is much appreciated.

Aucun commentaire:

Enregistrer un commentaire