Page 75 - MSDN Magazine, May 2017
P. 75
multicolor
hit-
highlighting
easy
options
®
• it defines a test, consisting of a description and a block of code (which, not surprisingly, is the test in question) to run. • expect is a fluent interface, defining a set of expectations that should hold true; if they don’t, the test is considered to
have failed.
When run (using either npm test or ng test), a browser window
will open and indicate the passing nature—or not—of the code under test. If this process is left to run in the background, by the way, every time a file is changed after the transpiling is done (by the npm server or ng serve process), the tests will automatically run again, giving near-instant feedback on whether the code passes muster.
In this case, the two beforeEach blocks do some standard boilerplate setup, including passing in the owner data that would normally come through the template, and then testing to ensure that the owner data was successfully passed in, that currentYear was correctly calculated, and that the <p> tag in the template, when rendered, will contain the right parts of the copyright message.
And then, of course, the browser window that contains the whole application should also display the new message.
Wrapping Up
At a certain point during every would-be Angular developer’s journey through the opening steps of Angular, there comes a point where the cognitive overhead seems so much higher than the benefits; “After all,” they might muse, “all I really wanted to do was put a copyright message on the bottom of the page!” This is where Angular, like many environments, can be deceiving, in that it might seem to make simple things difficult. Truthfully, that’s not entirely true—you could easily have just dropped the footer on the bottom of the AppComponent in raw HTML and static text, and then you’d have to change it next year, then again when the com- pany gets acquired, and the year after that when the date changes again, and the year after that and so on.
The act of constructing a component is never as freely undertaken as the act of simply “dropping some HTML” onto the page. The pain will come in time, however, as the complexity of the application scales up and developers are forced to remember every page on which the footer appears; by encapsulating the footer into a component, the developer can just use it without having to worry about how the footer comes to decide what message will be displayed. And, just the same, if some later legal scenario requires a more compre- hensive message, such as including the license model under which this page is offered to the world, you can change it in one—and only one—place, and that change will silently ripple through the rest of the system without requiring manual intervention.
There’s still much more to explore. In the meantime, happy coding! n
Ted Neward is a Seattle-based polytechnology consultant, speaker and mentor, currently working as the director of Developer Relations at Smartsheet.com. He has written more than 100 articles, authored and coauthored a dozen books, and works all over the world. Reach him at ted@tedneward.com or read his blog at blogs.tedneward.com.
ThaNks to the following technical expert for reviewing this article: Ward Bell msdnmagazine.com
Instantly Search Terabytes of Data
across a desktop, network, Internet or Intranet site with dtSearch enterprise and developer products
Over 25 search features, with
dtSearch’s document filters support popular file types, emails with multilevel attachments, databases, web data
Developers:
• APIs for .NET, Java and C++
• SDKs for Windows, UWP, Linux, Mac and Android
• See dtSearch.com for articles on faceted search, advanced data classification, working with SQL, NoSQL & other DBs, MS Azure, etc.
Visit dtSearch.com for
• hundreds of reviews and case studies • fully-functional evaluations
The Smart Choice for Text Retrieval® since 1991
dtSearch.com 1-800-IT-FINDS