javascript - AngularJS factory unit testing with dependencies -


i trying test angularjs factories jasmine. works fine factories don't have dependencies. 1 of factories uses angular material's $mdtoast dependency.

the factory:

(function() {    'use strict';      angular      .module('mymodule')      .factory('toastfactory', toastfactory);      toastfactory.$inject = ['$mdtoast'];      function toastfactory($mdtoast) {      var service = {        showtoast1: showtoast1,        showtoast2: showtoast2      };        return service        function showtoast1() {        return $mdtoast.show($mdtoast.build({          templateurl: 'path'        }));      }        function showtoast2() {        return $mdtoast.show($mdtoast.build({          templateurl: 'path'        }));      }    }  })();

and here 1 of working tests factory without dependencies.

describe('myfactory', function() {    //injector service    var $injector;      //set module    beforeeach(function() {      angular.module('mymodule');    });      //inject injector service    beforeeach(inject(function() {      $injector = angular.injector(['mymodule']);    }));        describe('sampletest', function() {      it('should true', function() {        //arrange        var factory = $injector.get('myfactory');          //act        var res = factory.testmethod();          //assert        expect(res).tobe(true);      });    });  })

i know how controllers, not factories.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -