HTML and CSS Reference
In-Depth Information
12.5 Using the Ajax API
As crude as it is, tddjs.ajax.get is now complete enough that we expect it to
be functional. We have built it step-by-step in small iterations from the ground up,
and have covered the basic happy path. It's time to take it for a spin, to verify that
it actually runs in the real world.
12.5.1 The Integration Test
To use the API we need an HTML page to host the test. The test page will make a sim-
ple request for another HTML page and add the results to the DOM. The test page
can be viewed in Listing 12.37 with the test script, successful _ get _ test.js ,
following in Listing 12.38.
Listing 12.37 Test HTML document
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type"
content="text/html; charset=utf-8">
<title>Ajax Test</title>
</head>
<body onload="startSuccessfulGetTest()">
<h1>Ajax Test</h1>
<div id="output"></div>
<script type="text/javascript"
src="../lib/tdd.js"></script>
<script type="text/javascript"
src="../src/ajax.js"></script>
<script type="text/javascript"
src="../src/request.js"></script>
<script type="text/javascript"
src="successful_get_test.js"></script>
</body>
</html>
Listing 12.38 The integration test script
function startSuccessfulGetTest() {
var output = document.getElementById("output");
if (!output) {
return;
}
 
 
Search WWH ::




Custom Search