Acceptance criterion
To demonstrate Jasmine support of asynchronous testing, we are going to implement the following acceptance criterion:
Stock when fetched, should update its share price
Using the techniques we have showed you until now, you could write this acceptance criterion in StockSpec.js
, inside the spec
folder file, as follows:
describe("Stock", function() { var stock; var originalSharePrice = 0; beforeEach(function() { stock = new Stock({ symbol: 'AOUE', sharePrice: originalSharePrice }); }); it("should have a share price", function() { expect(stock.sharePrice).toEqual(originalSharePrice); }); describe("when fetched", function() { var fetched = false; beforeEach(function() { stock.fetch(); }); it("should update its share price", function() { expect(stock.sharePrice).toEqual(20.18); }); }); });
That would lead to the implementation of the fetch
function from...