Jasmine is a behavior driven development framework for JavaScript proving functions to help structure tests and making assertions.
<html>
<head>
<link rel="stylesheet" type="text/css" href="lib/jasmine-2.3.4/jasmine.css" />
<script type="text/javascript" src="lib/jasmine-2.3.4/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-2.3.4/jasmine-html.js"></script>
<script type="text/javascript" src="lib/jasmine-2.3.4/boot.js"></script>
<!-- include source files -->
<script type="text/javascript" src="utility.js"></script>
<!-- include specs -->
<script type="text/javascript" src="some.tests.js"></script>
</head>
...
</html>
utility.js
function Greet(who) {
if (!who)
return 'Hello what is your name?';
return 'Hello ' + who;
}
some.tests.js
- describe word used to group tests
- Individual tests (specs) defined with call to the it method
- Assertion done with the expect method
describe("A suite of specs", function() {
it("contains spec with an expectation that fails", function() {
expect(false).toBe(true);
});
it("contains spec with an expectativon that passes", function() {
expect(true).toBe(true);
});
it("utility method should return greeting", function () {
expect(Greet("Craig")).toMatch("Hello Craig");
});
});