javascript - currentSpec in Jasmine 2 is undefined -
i want upgrade test suite latest jasmine version 2.3.4. have custom helper methods testing angularjs stuff inside spy_helper.js
this:
(function() { this.stubpromise = function(service, functionname) { var $q = jasmine.getenv().currentspec.$injector.get("$q") var $rootscope = jasmine.getenv().currentspec.$injector.get("$rootscope") var deferred = $q.defer(); var spy = spyon(service, functionname).andreturn(deferred.promise); spy.andresolvewith = function(value) { deferred.resolve(value); $rootscope.$apply(); return spy; }; spy.andrejectwith = function(value) { deferred.reject(value); $rootscope.$apply(); return spy; }; return spy; }; }).call(this); // inside test can stubpromise(someservice, 'foobar').andresolvewith("test");
the helper stubs promise , resolves or rejects promise. have bunch of such helpers.
the problem jasmine 2 is, jasmine.getenv().currentspec
undefined
. intended jasmine 2 developers, far know.
but how adapt helpers jasmine 2? extend arguments $injector
or $q
, $rootscope
, result in unhandy tests stubpromise(someservice, 'foobar', $injector).andresolvewith("test");
, have inject $injector
on top of every test.
so, there way angular's $injector
inside helpers?
furthermore in other helpers, need catch after
method of spec, check if expected spies on promises called jasmine.getenv().currentspec.after(flush);
any appreciated, because helpers saved me lot of time, , i'd not happy rewrite of them or throw them out. maybe there library out there, similar (and didn't know it).
Comments
Post a Comment