Có 20+ tài liệu thuộc chủ đề "kĩ thuật cắt html"
tailieu.vn Xem trực tuyến Tải xuống
005.13’3–dc . 1.3 Test Functions, Cases, and Suites 11 1.3.1 Setup and Teardown 13 1.4 Integration Tests 14. 4.1.1 Pitfalls of Programming by Observation 58 4.1.2 The Sweet Spot for Learning Tests 59. 5.3.1 Execution Contexts 81 5.3.2 The Variable Object 81 5.3.3 The Activation Object 82 5.3.4 The Global Object 82 5.3.5 The Scope Chain 83. 5.3.6 Function Expressions...
tailieu.vn Xem trực tuyến Tải xuống
While working through some of JavaScript’s finer points, I’ll use unit tests to show you how the language behaves, and we’ll take the opportunity to let tests drive us through the implementation of some helper utilities, which we’ll use throughout Part III.. In this part we’ll tackle a series of small projects in varying environments. We’ll see how to develop...
tailieu.vn Xem trực tuyến Tải xuống
Listing 1.12 shows the augmented testCase function that checks if the test case has setUp and tearDown , and if so, runs them at the appropriate times.. Using the new setUp method, we can add an object property to hold the test fixture, as shown in Listing 1.13. Listing 1.13 Using setUp in the strftime test case testCase("strftime test",. Listing...
tailieu.vn Xem trực tuyến Tải xuống
On the book’s website 1 you will find a guide to running the Coverage plugin for JsTestDriver as well as a guide on how to run JsTestDriver tests in the open source continuous integration server Hudson.. In the next chapter we will have a look at some other ways to utilize unit tests before we move on to Part II,...
tailieu.vn Xem trực tuyến Tải xuống
ptg Listing 5.1 A function declaration. The function declaration starts with the keyword function , followed by an identifier, assert in the above example. The function may define one or more formal parameters, i.e., named arguments. Finally, the function has a body enclosed in brackets. If no return statement is present, or if it’s present without an expression, the function...
tailieu.vn Xem trực tuyến Tải xuống
Listing 6.1 shows a rough outline.. Listing 6.1 Lightbox pseudo code var lightbox. var lb = Object.create(lightbox);. Object.extend(lb, options);. Listing 6.2 shows the workaround.. Listing 6.2 Calling open through an anonymous proxy function function anchorLightbox(anchor, options). 6.1.3 Function.prototype.bind. ECMAScript 5 provides the Function.prototype.bind function, which is also found in some form in most modern JavaScript libraries. Listing 6.3 Using bind....
tailieu.vn Xem trực tuyến Tải xuống
Listing 6.26 Memoizing the Fibonacci sequence in a closure var fibonacci = (function. Again, we will add a function to Function.prototype to help separate concerns.. The memoize method in Listing 6.27 is capable of wrapping a method, adding memoization without cluttering the calculation logic.. Listing 6.27 A general purpose memoize method if (!Function.prototype.memoize). Function.prototype.memoize = function. ptg This method offers...
tailieu.vn Xem trực tuyến Tải xuống
ptg Circle.prototype.area = function. Listing 7.17 shows a simple test to verify that objects do indeed inherit the methods.. Listing 7.17 Testing Circle.prototype.diameter. "test should inherit properties from Circle.prototype":. Repeating Circle.prototype quickly becomes cumbersome and expensive (in terms of bytes to go over the wire) when adding more than a few properties to the prototype. Listing 7.18 shows the shortest...
tailieu.vn Xem trực tuyến Tải xuống
This means that we can borrow methods from Array.prototype by calling them with arguments as this, as seen in Listing 7.50.. Listing 7.50 Borrowing from Array.prototype. Listing 7.51 shows an example.. Listing 7.51 Borrowing explicitly. Listing 7.52 Initial test case for tddjs.extend TestCase("ObjectExtendTest",. assertEquals("function", typeof object.getName);. assertEquals("function", typeof object.setName);. Listing 7.53 Initial implementation of tddjs.extend tddjs.extend = (function. The next...
tailieu.vn Xem trực tuyến Tải xuống
Listing 8.19 shows the new behavior compared to the current one.. Listing 8.19 Using the same identifier for more than one formal parameter. Attempts to access the caller or callee properties of the arguments object will throw a TypeError in strict mode.. Modify a formal parameter, and the value in the corresponding index of the argument object is modified too....
tailieu.vn Xem trực tuyến Tải xuống
Listing 9.10 Using the tab controller (function. var dom = tddjs.dom;. It then traverses the element’s parent until it finds a div element. typeof element.href. var target = element.href.replace. All the style rules are prefixed with “.js-tabs”, which means that they will only take effect if the script in Listing 9.10 completes successfully. Feature Detection. 10.1 Browser Sniffing. 10.1.1 User...
tailieu.vn Xem trực tuyến Tải xuống
observable.notifyObservers. 11.1 The Observer in JavaScript. 11.1.1 The Observable Library. As we gain confidence in our code and the process, we will gradually increase the size of our steps when circumstances allow it (i.e., the code to implement is trivial enough). 11.1 The Observer in JavaScript 221. 11.1.2 Setting up the Environment. Listing 11.1 shows the initial project layout.. Listing...
tailieu.vn Xem trực tuyến Tải xuống
11.5 Error Handling 233. Luckily, the implementation is fairly trivial, as seen in Listing 11.27.. Listing 11.27 Throwing an exception when adding non-callable observers function addObserver(observer). this.observers.push(observer);. 11.5.2 Misbehaving Observers. Listing 11.28 shows a test that expects all the observers to be called even if one of them throws an exception.. Listing 11.28 Expecting notifyObservers to survive misbehaving observers. var...
tailieu.vn Xem trực tuyến Tải xuống
12.3.3 Implementing tddjs.ajax.create. Listing 12.6 Creating an XMLHttpRequest object. Listing 12.7 improves the method.. ptg Listing 12.7 Checking for support upfront. ajax.create = options[i];. 12.3.4 Stronger Feature Detection. However, the checks we did in Listing 12.3 are really feature tests that verify the capa- bilities of the returned object. For this reason, Listing 12.8 performs the same tests in the...
tailieu.vn Xem trực tuyến Tải xuống
12.5.4 Local Requests. We will add support for local requests by checking if the script is running locally and that the status code is not set, as the test in Listing 12.44 shows.. Listing 12.44 Making sure the success handler is called for local requests. ajax.get("file.html". Listing 12.45 shows the updated ready state change handler.. Listing 12.45 Allow local requests...
tailieu.vn Xem trực tuyến Tải xuống
13.1 Polling for Data. 13.1.1 Project Layout. The initial project layout can be seen in Listing 13.1 and is available for download from the book’s website. Listing 13.1 Directory layout for the poller project chris@laptop:~/projects/poller $ tree. ajax.js. poller.js. The solution is to manually specify the tdd.js file first, then load the remaining lib files, as seen in Listing 13.2.....
tailieu.vn Xem trực tuyến Tải xuống
13.1 Polling for Data 313. Next up, Listing 13.32 makes sure the url property is set on the poller. Listing 13.32 Expecting the url property to be set. Implementing this test requires two additional lines, as in Listing 13.33.. Listing 13.33 Setting the URL function poll(url, options). Listing 13.34 shows the final version of ajax.poll . Listing 13.34 Final version...
tailieu.vn Xem trực tuyến Tải xuống
13.4 The Comet Client 333. if (!this.url). if (!this.poller). this.poller = ajax.poll(this.url. this.dispatch(JSON.parse(xhr.responseText));. this.client.url = "/my/url";. this.client.dispatch = stubFn();. this.client.connect();. this.xhr.complete(200, "OK");. assertFalse(this.client.dispatch.called);. this.poller = ajax.json.poll(this.url. this.dispatch(jsonData);. 13.4 The Comet Client 335. With long polling, the client polls the server. assertNotUndefined(this.xhr.headers["X-Access-Token"]);. this.xhr.complete(200, JSON.stringify(data));. var headers = this.xhr.headers;. 13.4 The Comet Client 337. this.dispatch(data);. Server-Side JavaScript with Node.js. 14.1 The Node.js...
tailieu.vn Xem trực tuyến Tải xuống
14.2 The Controller 353. We can fix the issue by moving the chatRoom stub into setUp as Listing 14.18 does.. Listing 14.18 Sharing the chatRoom stub function controllerSetUp(). Listing 14.19 shows the updated tests.. Listing 14.19 Cleaning up post tests function controllerSetUp(). 14.2.4.3 Malicious Data. This can lead to all kinds of scary situations, for instance consider the effects of...
tailieu.vn Xem trực tuyến Tải xuống
14.5 Event Emitters 373. Listing 14.54 Expecting chatRoom to be event emitter testCase(exports, "chatRoom",. We can pass this test by popping EventEmitter.prototype in as chat- Room ’s prototype, as seen in Listing 14.55.. Listing 14.55 chatRoom inheriting from EventEmitter.prototype. Listing 14.56 chatRoom defined with property descriptors. Listing 14.57 shows the test.. Listing 14.57 Expecting addMessage to emit a “message” event...