5.11. Testing JavaScript
JavaScript has always been an important aspect of web development, but in the past few years developers have been creating more JavaScript code than ever before. When the term AJAX (Asynchronous JavaScript and XML) became a buzz word, developers found themselves having to learn exactly how JavaScript worked. Many new frameworks, such as jQuery and Prototype, were introduced to help ease the pain that developers were feeling when trying to create JavaScript. For some reason JavaScript has received a bad reputation. Many developers complain that it is difficult to write and hard to maintain, but in reality, if written correctly, JavaScript can be a very useful and powerful language.
Many developers are not even aware of the different testing frameworks that exist, let alone that many developers are creating their JavaScript using TDD methods. As with server-side code, many of the SOLID principles discussed in Chapter 2 apply to JavaScript. Much of the JavaScript that you see from day-to-day is contained in the HTML that calls the script. When JavaScript is organized in this way, it is very difficult to test. Some web developers complain that having an HTML page that makes many requests to the server to download multiple JavaScript files slows down the web page. They are correct, but how much does it actually slow down the web page? You'll explore this topic in detail in Chapter 8, but for now you should focus on creating code that is testable.
Currently ...
Get Testing ASP.NET Web Applications 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.