To understand the concept of behavior checking, let's revisit an example presented in Chapter 3, Testing Frontend Code, and test the observable behavior of the NewInvestmentView
test suite:
describe("NewInvestmentView", function() { var view; // setup and other specs ... describe("with its inputs correctly filled", function() { // setup and other specs ... describe("and when an investment is created", function() { var callbackSpy; var investment; beforeEach(function() { callbackSpy = jasmine.createSpy('callback'); view.onCreate(callbackSpy); investment = view.create(); }); it("should invoke the 'onCreate' callback with the created investment", function() { expect(callbackSpy).toHaveBeenCalled(); expect(callbackSpy).toHaveBeenCalledWith(investment); }); }); }); });
During the spec setup, it creates a new Jasmine spy using the jasmine.createSpy
function while passing a name...