How not.toThrow

2,864 views
Skip to first unread message

robertj

unread,
Aug 30, 2011, 7:43:40 AM8/30/11
to jasmi...@googlegroups.com
Hi,

how can I test for the absence of any exception.
I'd like to do something like this 

expect(function(){a.dontFail()}).not.toThrowException();
expect(function(){a.kaboom()}).toThrowException(ex);

thanks

best regards

Robert

Alex Chaffee

unread,
Aug 30, 2011, 1:29:41 PM8/30/11
to jasmi...@googlegroups.com
On Tue, Aug 30, 2011 at 4:43 AM, robertj <rob...@robkuz.com> wrote:
> expect(function(){a.dontFail()}).not.toThrowException();

Try this:

a.dontFail()

If it raises an exception, the test will fail, which is what you want.

Essentially, every statement in every program is wrapped in a
expect().not.toThrowException() :-)

--
Alex Chaffee - al...@stinky.com
http://alexch.github.com
http://twitter.com/alexch

robertj

unread,
Aug 31, 2011, 10:22:50 AM8/31/11
to jasmi...@googlegroups.com
Hi Alex,

yeah - obviously every statement is should in general not.throw anything ;-)
Its part of a paranoid testing strategy

Best

Robert
Reply all
Reply to author
Forward
0 new messages