1

I am using JsTestDriver for unit tests in JS. One section of my code uses a confirm box to allow users to confirm or cancel a decision.

How to I test both the confirm and cancel selections of this confirm box automatically within the scope of JsTestDriver

  • You probably can't. confirm boxes are not in the DOM _AND_ block javascript. They are also horrible design. You should probably use a modal popup instead – Raynos Nov 01 '11 at 10:46

2 Answers2

3

You can override window.confirm in your test prior to triggering the prompt

window.confirm = function(msg) {
    // This will get executed instead of showing a browser prompt message
    return true;
}
andyzinsser
  • 2,463
  • 2
  • 18
  • 18
0

Ok, the way I handled this was to use Jack.js mocking library to mock the confirm function returning both True and False in turn.

jack.expect('confirm')
    .exactly('1 time')
    .mock(function(strMessage) {
        return true;
    }
);