Cheat sheet: Jasmine(testing framework for javascript) - agile-organizer/Huddle-Skeleton---Base-- GitHub Wiki
- Download the Jasmine library from https://github.com/pivotal/jasmine/downloads, and extract the content.
- Create a folder named test under the root folder of the project.
- Copy lib folder and SpecRunner.html from Jasmine and paste them to the test folder.
Open SpecRunner.html and modify the source property of the script tag under comment of <!– include source files here… –> to point to your source file to be tested. For example, your include statement may look like this
<script type="text/javascript" src="../public/javascripts/core.js"></script>
Modify the source property of the script tag under comment of <!– include spec files here… –> to point to your test file. Your include statement may look like this
<script type="text/javascript" src="javascripts/core_spec.js"></script>
An example of test in Jasmine would look like following
describe("description of a test suit", function() { it("description of a test case", function() { // Your actual test goes here expect(variableOrExpression).toBe(expectedValue); }); });
For example, function getImagePath is supposed to return the full image path given the id of an image. Here is a complete test for this function.
describe("test suit for core.js", function() { it("should return the full image path", function() { expect(getImagePath(1)).toBe("/images/1.jpg"); }); });
- Open your browser and open SpecRunnder.html, you will see the test report.