Basic View coding rules
Now, it is time to start coding the first View component. To help us 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'); ...
Get Jasmine JavaScript Testing - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.