|Language:||English, Spanish, French|
|Distribution:||Free* [*Sign up for free]|
This practical guide shows you how to write unit tests with Jasmine that automatically check for bugs in your application.
Only 40 pages long. If you are after an offline documentation of the Jasmine library then this book is for you. Apr 16, Daniel Aguilar rated it liked it Shelves: It has some typos and obscure sections I found the one on Spies quite convoluted , and doesn't really provide a good baseline on the subject, but as said, as a simple reference it works fine and gets read in a single sitting. Sep 17, Daniel Brubeck rated it liked it Shelves: I liked this book, its very concise and all the topics are explained very well; I would recommend this book for people that already knows about TDD and just need the concepts from Jasmine.
I just think that it would had be nice if the author gave more examples on the spies and asynchronous types. Aug 25, Katherine rated it liked it.
I read this because of my current task. It is a short version of a documentation. In a way, the fact that it is short makes it great but then I did not get the absolute basic introduction I need to learn about testing with fixtures. Sep 29, Aelena rated it liked it.
As noted earlier, when jasmine runs it searches for all tests in this directory. How to use Jasmine to test Node. In our example below, we are going to define a module which add 2 numbers which need to be tested. We will then define a separate code file with the test code and then use jasmine to test the Add function accordingly. Step 1 Define the code which needs to be tested. We are going to define a function which will add 2 numbers and return the result. This code is going to be written in a file called "Add.
We are then defining a function called 'AddNumber. The function is added to the module "exports" to make the function as a public function that can be accessed by other application modules. We are finally making our function return the added value of the parameters. Step 2 Next we need to define our jasmine test code which will be used to test our "Add" function In the Add.
The below code needs to put in a file called add-spec.
Note: - The word 'spec' needs to be added to the test file so that it can be detected by jasmine. AddNumber 5,6 ; expect value. We are now creating our test module. The first part of the test module is to describe a method which basically gives a name for our test.
In this case, the name of our test is "Addition". The next bit is to give a description for our test using the 'it' method. We now invoke our Addnumber method and send in 2 parameters 5 and 6. This will be passed to our Addnumber method in the App.
The return value is then stored in a variable called value. The final step is to do the comparison or our actual test.
Since we expect the value returned by the Addnumber function to be 11, we define this using the method expect value. Output In order to run the test, one needs to run the command jasmine. The below screenshot shows that after the jasmine command is run , it will detect that there is a test called add-spec.