Difference between toBeTruthy and toBe(true)
Uses Jasmine 2.0 CDN from http://cdnjs.com/libraries/jasmine
by Joe Wilson
HTML
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine-html.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/boot.js"></script>
JavaScript
// Code under test
var MyApp = function () {
var isValid = function (scaleMin, scaleMax) {
if (scaleMax <= scaleMin) {
return "Scale max must be greater than Scale min.";
}
return true;
};
return {
isValid: isValid
};
};
// Specs
describe("isValid", function () {
var myApp = new MyApp();
it("Should be valid when scale min/max are both 0", function () {
var scaleMin = 0,
scaleMax = 0;
expect(myApp.isValid(scaleMin, scaleMax)).toBeTruthy();
});
it("Should be valid when scale min is less than scaleMax", function () {
var scaleMin = 0,
scaleMax = 1;
expect(myApp.isValid(scaleMin, scaleMax)).toBeTruthy();
});
it("Should be invalid when scale min is equal to scaleMax", function () {
var scaleMin = 1,
scaleMax = 1;
expect(myApp.isValid(scaleMin, scaleMax)).toBe("Scale max must be greater than Scale min.");
});
it("Should be invalid when scale min is greater than scaleMax", function () {
var scaleMin = 1,
scaleMax = 0;
expect(myApp.isValid(scaleMin, scaleMax)).toBe("Scale max must be greater than Scale min.");
});
});