JavaScript Cookbook, 2nd Edition

JavaScript Cookbook, 2nd EditionReviews
Author: Shelley Powers
Pub Date: 2015
ISBN: 978-1-49190-188-5
Pages: 634
Language: English
Format: PDF/EPUB
Size: 19 Mb

Download

Problem solving with JavaScript is a lot trickier now that its use has expanded considerably in size, scope, and complexity. This cookbook has your back, with recipes for common tasks across the JavaScript world, whether you’re working in the browser, the server, or a mobile environment. Each recipe includes reusable code and practical advice for tackling JavaScript objects, Node, Ajax, JSON, data persistence, graphical and media applications, complex frameworks, modular JavaScript, APIs, and many related technologies.
Aimed at people who have some experience with JavaScript, the first part covers traditional uses of JavaScript, along with new ideas and improved functionality. The second part dives into the server, mobile development, and a plethora of leading-edge tools. You’ll save time – and learn more about JavaScript in the process.

+

Solution
Use an emulating tool or browser testing service that can test your application in all of your environments. These aids help you not only test the integrity of the code, but the appearance and behavior of your user interface.
Discussion
In-house testing works if your customer uses a finite set of machines and you can easily re-create the environments, or you work for a large enough corporation that can afford to set up one of everything. For most other situations, you either need to use some form of emulation tool or a service.
This is especially critical when you’re testing client-side JavaScript. Web or mobile development environments are undergoing rapid change, and a technology you think is
safe to use may end up blowing up in your face when you test the functionality inenvironments other than the ones you use for development.
Emulators are a favorite for mobile developers. Some are specific to a browser, such as Ripple for Chrome. Others are standalone tools like Opera Mobile Classic Emulator,
shown in Figure 6-2or the Android Emulator (part of the Android SDK).
Download the Opera emulator, or access Ripple for Chrome at the Google Web Store. An excellent resource for discovering emulators is the Emulator page at “Breaking the Mobile Web”.
A variation for testing mobile applications is a simulator, which simulates some of the environment but doesn’t fully emulate it at the hardware level. An example of a simulator is Apple’s iOS Simulator.

If you’re more interested in testing how the client interface works in different browsers and different environments, then you’ll want to look for a cross-browser testing service (BrowserStackor Sauce Labs), or an application like Ghostlab (demonstrated in Figure 6-3). You might also consider automated testing services, where you create a
script that’s automatically run (Selenium is an example). The key is to look for a service or tool that provides interactive testing—not one that is primarily used to check out the design of the page in different environments. One advantage to some of these tools is they provide testing in both browser and mobile environments. The disadvantage is cost: either a one-time cost for an application, or a monthly or annual fee for a service. The only tool that didn’t have a price tag attached is IE NetRenderer, which allows you to test your website in every variation of IE, from versions 5.5 through 11.

One of the services I have used is BrowserStack. It, like most of the other tools and services, provides a trial period for testing the service. In addition, it also works with
testing environments, such as QUnit, demonstrated earlier in the chapter. BrowserStack offers a variety of services, including screenshots of your site across several devices — desktop or mobile. From a client-side JavaScript developer’s perspective, the service we’re most interested in is the Live testing, where we can pick an OS and a
browser and test our client application, directly. Figure 6-4 demonstrates running an application in Safari on OS X — an environment I don’t have access to.