Created
November 7, 2014 17:09
-
-
Save mattscilipoti/935b41d202da39de0f49 to your computer and use it in GitHub Desktop.
Using Jasmine from jasmine-node OR html (interchangeably)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof window === 'undefined') { | |
// not in browser, use node | |
var Geometry = require('./geometry.js'); | |
var Rectangle = Geometry.Rectangle; | |
} | |
describe("Rectangle", function() { | |
describe("isSquare", function() { | |
it("should be true for a 4x4 rectangle", function() { | |
var shape = new Rectangle(4, 4); | |
expect(shape.isSquare()).toBeTruthy(); | |
}); | |
it("should be false for a 4x3 rectangle", function() { | |
var shape = new Rectangle(4, 3); | |
expect(shape.isSquare()).toBeFalsy(); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Rectangle(length, width) { | |
this.length = length; | |
this.width = width; | |
} | |
Rectangle.prototype.isSquare = function() { | |
return (this.length == this.width); | |
}; | |
function Triangle(sideA, sideB, sideC) { | |
this.sideA = sideA; | |
this.sideB = sideB; | |
this.sideC = sideC; | |
} | |
function LineSegment(x1, y1, x2, y2) { | |
this.x1 = x1; | |
this.y1 = y1; | |
this.x2 = x2; | |
this.y2 = y2; | |
} | |
// make available externally (via node) | |
module.exports = { | |
Rectangle: Rectangle, | |
Triangle: Triangle, | |
LineSegment: LineSegment | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>geometry specs</title> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.css"> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/jasmine-html.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.0.0/boot.js"></script> | |
<!-- javascript source files here --> | |
<script src="geometry.js" type="text/javascript"></script> | |
<!-- jasmine spec files here --> | |
<script src="geometry-spec.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<h1>Geometry Specs</h1> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment