javascript - $provide more than 1 value to test in a describe -
i have karma/jasmine test angular directive:
describe('placeholder directive', function() { // bindable members var element; // load module beforeeach(angular.mock.module('app')); // mock service response beforeeach(module(function($provide) { $provide.value('placeholdersupportservice', function() { return false; }); })); // bind references global variables beforeeach(inject(function($compile, $rootscope) { element = $compile('<input name="test" placeholder="test" />')($rootscope); $rootscope.$digest(); })); // check correct html rendered it('renders placeholder input value when placeholder not supported', inject(function($timeout) { $timeout.flush(); expect(element[0].value).tobe('test'); })); });
it works want. however, have forced value of placeholdersupportservice()
false
. want run second test have value true
. can't seem access $provide
within it
statement, how do this?
you tell placeholdersupportservice
return variable. , then, on test block, change value of variable. should solve problem. here example:
describe('placeholder directive', function() { // bindable members var element; var providerresult = false; //here variable change. // load module beforeeach(angular.mock.module('app')); // mock service response beforeeach(module(function($provide) { $provide.value('placeholdersupportservice', function() { return providerresult; }); })); // check correct html rendered it('renders placeholder input value when placeholder not supported', inject(function($timeout) { element = $compile('<input name="test" placeholder="test" />')($rootscope); $rootscope.$digest(); $timeout.flush(); expect(element[0].value).tobe('test'); })); // check correct html rendered it('renders placeholder input value when placeholder supported', inject(function($timeout) { providerresult = true; //here change result of placeholdersupportservice element = $compile('<input name="test" placeholder="test" />')($rootscope); $rootscope.$digest(); $timeout.flush(); expect(element[0].value).tobe('test'); })); });
Comments
Post a Comment