Reputation: 4701
How can I cause a break when console.assert()
fails (other than replacing assert function with my own and setting breakpoint there) ?
Upvotes: 7
Views: 2161
Reputation: 9375
When you first fire up the Chrome Developer Tool
Click on the pause icon that says on mouseover
"Do not pause on exceptions. Click to pause on all exceptions"
at the very bottom bar of the Chrome Developer Tool near the left side. If you can not find that icon, press the Sources
tab within the Chrome Developer Tool.
That icon should turn blue. If it doesn't turn blue the first time, click on it a second time. Then, it will pause even on console.assert(false);
Upvotes: 6
Reputation: 4896
I don't know of any way to break automatically on failed assert()
s, at least in Chrome/Safari.
But I think replacing with your own is actually almost as good:
var nativeAssert = console.assert;
function assertWrapper(expr) {
nativeAssert.apply(this, arguments);
if (!expr) {
"";
}
}
console.assert = assertWrapper;
Then you can just place a breakpoint on the ""
line to catch all failures, while still getting the standard console output you expect.
Upvotes: 1