Get help with testing, discuss unit testing strategies etc.


Post by carina »

Hi,

I just started experimenting with Siesta and wanted to port some of our Jasmine tests to Siesta.

I want to test for an error to be thrown. Somewhere in the code we call Ext.Error.raise (which will subsequently throw an error) and I wanted to check for this with throwsOk:
   t.throwsOk(MyNamespace.lib.data.DateUtil.stringToDate('2012-04-19 11:30:24'),
     /some error message/,
     "When a string like '2012-04-19 11:30:24' is passed without a format string it must throw an exception");
But unfortunately, this test fails and the execution of all subsequent checks is stopped and I can see the message "test suite threw an exception" with my error message that I passed to Ext.Error.raise. I'm expecting throwsOk to catch the error and the test to pass. Am I doing something wrong?

Thanks in advance :)

Carina

Post by nickolay »

Hi,

And welcome, would be great to hear your feedback about Jasmine -> Siesta migration.

About your question - just supply the function to the `throwsOk`:
    t.throwsOk(
        function () {
            MyNamespace.lib.data.DateUtil.stringToDate('2012-04-19 11:30:24')
        }, 
        /some error message/,
        "When a string like '2012-04-19 11:30:24' is passed without a format string it must throw an exception"
    )

Post by carina »

Oh my, this is embarrassing. Of course it works now, thanks for the fast reply!

I'll keep you updated about the progress. What I can tell you so far is that I had everything up and running the way I wanted it (test cases in combination with the entire application running and visible in the background) in less than an hour instead of one day with Jasmine where I had to try a couple of different approaches first.

I met Mats today at the SourceDevCon and he mentioned something about a BDD layer that might be available in the near future. That's at the moment the main thing I would miss when migrating away from Jasmine. So I'm definitely looking forward to that.

Regards,
Carina

Post by mats »

Hey, great to meet you and nice to hear that you already got started! Let us know if you and have any suggestions for improvements :)

Post Reply