Ho creato un servizio Env
che racchiude informazioni sull'ambiente e attualmente sto utilizzando $location.host()
per determinare l'ambiente in cui mi trovo. Come faccio a prenderlo in giro nei miei test?
ho letto https://groups.google.com/forum/?fromgroups#!topic/angular/F0jFWC4G9hI, ma non sembra funzionare, per esempio:
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();
});
});
});
Ho anche provato la variante $browser
, ma che non funziona neanche. Qualche idea?
Ho anche provato '$ browser.url()' come da http://www.thecssninja.com/javascript/angular -location-testing, ma anche questo non funziona. – zlog
Ho un problema simile, ho bisogno di iniettare $ posizione nel mio test dal momento che il servizio lo richiede. –
https://github.com/angular/angular.js/issues/493 –