O'Reilly logo

Jasmine JavaScript Testing by Paulo Ragonha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic View coding rules

Now it is time to start coding the first View component. To help you through the process we are going to lay two basic rules for View coding happiness:

  • The View should encapsulate a DOM element
  • Integrate Views with observers

So let's see how they work individually.

The View should encapsulate a DOM element

As mentioned earlier, a View is the behavior associated with a DOM element, so it makes sense to have this element related to the View. A good pattern is to pass a CSS selector in the View instantiation that indicates the element to which it should refer. Here is the spec for the NewInvestmentView component:

describe("NewInvestmentView", function() { var view; beforeEach(function() { loadFixtures('NewInvestmentView.html'); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required