我创建了一个包装环境信息的Env
服务,我目前使用$location.host()
来确定我所处的环境。我如何在我的测试中嘲笑它?
我读过https://groups.google.com/forum/?fromgroups#!topic/angular/F0jFWC4G9hI,但它似乎没有工作,例如:
describe("Env (environment) service", function() {
var Env;
beforeEach(module('App'));
beforeEach(inject(
['Env', function(e) {
Env = e;
}]
));
describe("for staging", function() {
beforeEach(inject(function($location, $rootScope) {
$location.host("http://staging-site.com");
$rootScope.$apply();
}));
it("returns envrionment as staging", function() {
expect(Env.environment).toEqual("staging");
});
it("returns .isStaging() as true", function() {
expect(Env.isStaging()).toBeTruthy();
});
});
});
我也试过$browser
变种,但也不管用。有任何想法吗?
我也试过'$ browser.url()'按http://www.thecssninja.com/javascript/angular位置测试,但这也行不通。 – zlog
我有类似的问题,我需要注入$位置到我的测试,因为服务需要它。 –
https://github.com/angular/angular.js/issues/493 –