vendredi 10 février 2017

Mock a module for jasmine tests

Vote count: 0

I am working on a enhancement which is in one module. I am using a cache service in my enhancement, which is in another module. Now to run jasmine test how do I mock the cache service module.

module cachemodule { 
export class CacheObject implements ng.ICacheObject {
static $inject = ['$angularCacheFactory'];
    constructor(
        private $cacheFactory: ng.ICacheFactoryService
    ) { }
public createCache = (id: string, options?: ICacheConfigOptions): ng.ICacheObject => {
        this.cacheId = id;
        return this.$cacheFactory(id, options);
    };
}}

and,

module mainmodule {
export MainClass {
 cacheObj: cachemodule .CacheObject; 
 this.cacheObj = new cachemodule.CacheObject($cacheFactory);
 this.service = this.cacheObj.createCache('FolderCache');
}}

I tried mocking it in normal way with angular.mock.module but i keep getting error - Module is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Any help is appreciated.

asked 41 secs ago

Let's block ads! (Why?)



Mock a module for jasmine tests

Aucun commentaire:

Enregistrer un commentaire