Jasmine is a really good testing tool for JavaScript. It's well known, well documented, widely used, and has personally helped me catch a lot of bugs before they've seen the light of day. Thank you to the Jasmine team for making a really good tool.
Jasmine has two areas where it can help developers better, and this project fills in those two gaps.
it ("Test emptying the shopping cart", function () {
const cart:ShoppingCart = new ShoppingCart();
cart.put (product1);
cart.put (product2);
cart.clear ();
expect (cart.numberOfItemsInCart ()).toEqual(0);
expect (cart.calculatePrice ()).toEqual(0);
});And then you get back the helpful error message: Expected undefined to equal 0.
This error message doesn't tell you which line brought back the wrong result.
Do I have a bug with the first call or the second call?
The expect (something()).method(somethingElse()) syntax is criticized for being unusual (although it does open up a great deal of flexibility).
it ("Test emptying the shopping cart", function () {
const cart:ShoppingCart = new ShoppingCart();
cart.put (product1);
cart.put (product2);
cart.clear ();
TestNumber.equals ("no items in cart", cart.numberOfItemsInCart (), 0);
TestNumber.equals ("empty cart should cost nothing", cart.calculatePrice (), 0);
});Returns the far better error message: Failed: empty cart should cost nothing - value was undefined expected 0
Because you can provide text with each failure message, knowing exactly which statement failed with the chance for the developer to provide intelligent comments makes for quicker and easier debugging.
| TestBoolean | ||
|---|---|---|
| true | TestBoolean.true ("Test failure message if this boolean isnt true", dataToTest); | |
| false | TestBoolean.false ("Test failure message if this boolean isnt false", dataToTest); | |
| equals | TestBoolean.equals ("Test failure message if these booleans arent equal", dataToTest, dataToTestAgainst); | |
| null | TestBoolean.null ("Test failure message if this boolean isnt null", dataToTest); | |
| undefined | TestBoolean.undefined ("Test failure message if this boolean isnt undefined", dataToTest); | |
| notNull | TestBoolean.notNull ("Test failure message if this boolean is null", dataToTest); | |
| notUndefined | TestBoolean.notUndefined ("Test failure message if this boolean is undefined", dataToTest); | |
| notNullOrUndefined | TestBoolean.notNullOrUndefined ("Test failure message if this boolean is null or undefined", dataToTest); |
| TestNumber | ||
|---|---|---|
| equals | TestNumber.equals ("Test failure message if these numbers arent equal", dataToTest, numberItHasToEqual); | |
| greaterThan | TestNumber.greaterThan ("Test failure message if dataToTest is not greater than numberItHasToBeGreaterThan", dataToTest, numberItHasToBeGreaterThan); | |
| lessThan | TestNumber.lessThan ("Test failure message if dataToTest is not greater than numberItHasToBeLessThan", dataToTest, numberItHasToBeLessThan); | |
| undefined | TestNumber.undefined ("Test failure message if this number isnt undefined", dataToTest); | |
| null | TestNumber.null ("Test failure message if this number isnt null", dataToTest); | |
| notEquals | TestNumber.notEquals ("Test failure message if these numbers are equal", dataToTest, numberItHasToEqual); | |
| notNullOrUndefined | TestNumber.notNullOrUndefined ("Test failure message if this number is null or undefined", dataToTest); | |
| notUndefined | TestNumber.notUndefined ("Test failure message if this number is undefined", dataToTest); | |
| notNull | TestNumber.notNull ("Test failure message if this number is null", dataToTest); |
| TestString | ||
|---|---|---|
| equals | TestString.equals ("Test failure message if these strings arent equal", dataToTest, stringItHasToEqual); | |
| null | TestString.null ("Test failure message if this string is not null", dataToTest); | |
| undefined | TestString.undefined ("Test failure message if this string is not undefined", dataToTest); | |
| notNull | TestString.notNull ("Test failure message if this string is null", dataToTest); | |
| notUndefined | TestString.notUndefined ("Test failure message if this string is undefined", dataToTest); | |
| notNullOrUndefined | TestString.notUndefined ("Test failure message if this string is null or undefined", dataToTest); |
| Test | ||
|---|---|---|
| equals | Test.equals ("Test failure message if these objects arent equal", dataToTest, stringItHasToEqual); | |
| null | Test.null ("Test failure message if this object is not null", dataToTest); | |
| undefined | Test.undefined ("Test failure message if this object is not undefined", dataToTest); | |
| notNull | Test.notNull ("Test failure message if this object is null", dataToTest); | |
| notUndefined | Test.notUndefined ("Test failure message if this object is undefined", dataToTest); | |
| notNullOrUndefined | Test.notNullOrUndefined ("Test failure message if this object is null or undefined", dataToTest); |