javascript - How would I test window prompts and confirms with Karma / Jasmine? -


i'm pretty new tdd , i've been doing programming prompts reddit learn it. 1 acronym generator asks string converted, displays it, , asks if user wants generate another.

my trouble don't know how write tests fill in prompt , hit ok button. select ok or cancel button when asked again.

(function(ns, undefined) {     ns.generateacronym = function()     {         var s = window.prompt("enter words converted acronym.");         var matches = s.match(/\b(\w)/g);         var acronym = matches.join("").touppercase();         if(window.confirm("your acronym is: "+acronym+". generate another?"))         {             ns.generateacronym();         }      };  })(window.pprompts = window.pprompts || {});   pprompts.generateacronym(); 

alright - think figured out. if has better methods, i'd love see/read them :)

i realize have put of 1 it block, seeing executed 2 of 2 success on executed 1 of 1 success.

describe('acronym generator', function() {      beforeeach(function()     {         spyon(window, "prompt").and.returnvalue("java script object notation");         spyon(window, "confirm");         pprompts.generateacronym();     });       it('should generate window prompt', function() {         expect(window.prompt).tohavebeencalledwith("enter words converted acronym.");     });      it('should generate confirm dialog proper acronym', function() {         expect(window.confirm).tohavebeencalledwith("your acronym is: json. generate another?");     }); }); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -