<!DOCTYPE html>
<html>
<head>
<link data-require="jasmine@2.4.1" data-semver="2.4.1" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.css" />
<script data-require="jasmine@2.4.1" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js"></script>
<script data-require="jasmine@2.4.1" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine-html.js"></script>
<script data-require="jasmine@2.4.1" data-semver="2.4.1" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/boot.js"></script>
<script src="car.js"></script>
<script src="car.spec.js"></script>
</head>
<body>
<h1>Hello Jasmine!</h1>
</body>
</html>
Car = (function () {
function Car (engine) {
this.engine = engine;
}
Car.prototype.drive = function (speed) {
this._lastSpeed = speed;
return 'Car with ' + this.engine + ' engine ' +
'drives at ' + speed + ' km/h.';
}
Object.defineProperty(Car.prototype, 'lastSpeed', {
get: function () {
return this._lastSpeed ? this._lastSpeed : 0;
},
enumerable: false,
configurable: true
});
return Car;
})();
'use strict';
describe('Car class', function () {
it('should define engine property when constructing car object', function () {
var car = new Car('V8');
expect(car.engine).toBeDefined();
expect(car.engine).not.toBeUndefined();
car = new Car();
expect(car.engine).not.toBeDefined();
expect(car.engine).toBeUndefined();
});
});