How to handle Confirm Box within JsTestDriver

599 Views Asked by At

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

2

There are 2 best solutions below

0
On BEST ANSWER

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;
    }
);
0
On

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;
}