jmdobry / angular-cache

angular-cache is a very useful replacement for the Angular 1 $cacheFactory.
http://jmdobry.github.io/angular-cache
MIT License
1.39k stars 156 forks source link

"cache already exists" error when unit testing with angular-mocks #236

Closed henrahmagix closed 8 years ago

henrahmagix commented 8 years ago

Since this uses CacheFactory that keeps caches = {} in memory outside of angular, caches persist across unit tests using angular + angular-mocks + karma. This means every test suite that uses CacheFactory must destroy the cache after every spec, like this:

afterEach(function () {
    myCacheThatMustBeInjected.destroy();
});

To make this simpler, the caches object can be reset when the root scope is destroyed, since that is only likely to happen in angular-mocks. Or there may be another method particular to angular-mocks that can be checked.

Will submit a pull-request soon =)

henrahmagix commented 8 years ago

👍