jasminekarma-jasminejsdatajs-data-angular

JS-Data slow jasmine tests after inject


I am having a JS-Data resource in angularjs, and every time I call inject on it in a (Jasmine) test, the test slows down, taking up to 700ms.

I am already doing an ejectAll() after each test. It is not doing any $http requests either, so I am out of clues...

Any ideas why JS-Data injections might be so slow in my tests?


Solution

  • Found it: in my resource definition I set the UseClass property to a model that changed the instance, replacing an array with a getter through Object.defineProperty. As stated here:

    The DS.change fires on a Resource whenever any item in the Store for that Resource changes.

    The getter resulted in JS-Data to think the instance changed, triggering an infinite digest loop. After 10 digests angular gives up, but it takes some time, leading to slow tests.

    Lesson learned: don't extend persistend DS model instances with getter properties, as they trigger infinite changes.