Đang chuẩn bị liên kết để tải về tài liệu:
Test Driven JavaScript Development- P15

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Test Driven JavaScript Development- P15:This book is about programming JavaScript for the real world, using the techniques and workflow suggested by Test-Driven Development. It is about gaining confidence in your code through test coverage, and gaining the ability to fearlessly refactor and organically evolve your code base. It is about writing modular and testable code. It is about writing JavaScript that works in a wide variety of environments and that doesn’t get in your user’s way. | 12.5 Using the Ajax API 273 requestComplete transport options transport.onreadystatechange tddjs.noop transport.send null . Adding these two lines makes the tests pass again. Re-running the massive request integration test in Internet Explorer confirms that the memory leak is now gone. 12.5.4 Local Requests The last issue with the current implementation is that it is unable to make local requests. Doing so results in no errors yet nothing happens. The reason for this is that the local file system has no concept of HTTP status codes so the status code is 0 when readyState is 4. Currently our implementation only accepts status code 200 which is insufficient in any case. 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 test should call success handler for local requests function this.xhr.readyState 4 this.xhr.status 0 var success stubFn tddjs.isLocal stubFn true ajax.get file.html success success this.xhr.onreadystatechange assert success.called The test assumes a helper method tddjs.isLocal to check if the script is running locally. Because we are stubbing it a reference to it is saved in the setup allowing it to be restored in tearDown as we did before. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. From the Library of WoweBook.Com 274 Abstracting Browser Differences Ajax To pass the test we will call the success callback whenever the request is for a local file and the status code is not set. Listing 12.45 shows the updated ready state change handler. Listing 12.45 Allow local requests to succeed function requestComplete transport options var status transport.status if status 200 tddjs.isLocal status if typeof options.success function options.success transport The implementation passes the test. In order to have this working in a browser as well we need to

Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.