Book Image

JavaScript Testing Beginner's Guide

By : Yuxian, Eugene Liang
Book Image

JavaScript Testing Beginner's Guide

By: Yuxian, Eugene Liang

Overview of this book

<p>JavaScript is an important part of web development in today’s Web 2.0 world. While there are many JavaScript frameworks in the market, learning to write, test, and debug JavaScript without the help of any framework will make you a better JavaScript developer. However, testing and debugging can be time consuming, tedious, and painful. This book will ease your woes by providing various testing strategies, advice, and tool guides that will make testing smooth and easy. This book shows you the most essential features of JavaScript, which you will be using in your daily development, testing, and debugging tasks. You will learn to use the most basic functions of JavaScript to perform ad hoc testing quickly and efficiently. This book is organized in an easy to follow, step-by-step tutorial style to maximize your learning. You will first learn about the different types of errors you will most often encounter as a JavaScript developer. You will also learn the most essential features of JavaScript through our easy to follow examples.As you go along, you will learn how to write better JavaScript code through validation. Learning how to write validated code alone will help you improve tremendously as a JavaScript developer and most importantly, to write JavaScript code that runs better, faster, and with less bugs.As our JavaScript program gets larger, we need better ways of testing our JavaScript code. You will learn how to go about various testing concepts and how to use them in your test plan. After which, you will learn how to implement the test plan for your code. To accommodate more complex JavaScript code, you will learn more about the built-in features of JavaScript to identify and catch different types of JavaScript error. Such information helps to spot the root of the problem so that you can act on it. Finally, you will learn how to make use of the built-in browser tools and other external tools to automate your testing process.</p>
Table of Contents (14 chapters)
JavaScript Testing
Credits
About the Author
About the Reviewers
Preface
Index

Time for action—debugging using Firefox's Venkman extension


We'll start off by setting breakpoints, before we go into greater details:

As with all debuggers, we can set a breakpoint by performing the following steps:

  1. Start by opening the file example.html, in Firefox.

  2. Open the JavaScript debugger, and the debugger window will be shown.

  3. When your see the debugger window, go to the Load Scripts panel and you will see the file example.html in it. Click on it and you will see the code being loaded in the Source Code panel.

  4. To set a breakpoint, click on the line at which you want the breakpoint to be set. For instance, I have set it on line 130, which contains the code: buildContent(answer, "minus");. You should see something like the following screenshot:

What just happened?

The first thing to note is that there is a white B within a red rectangle, as shown in the previous screenshot. This indicates that a breakpoint has been set.

In Venkman, there are times where you will see a white F within a...