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

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Test Driven JavaScript Development- P19: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. | 14.2 The Controller 353 Unfortunately this doesn t play out exactly as planned. The previous test which also calls post is now attempting to call addMessage on chatRoom which is undefined in that test. 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 . this.controller.chatRoom addMessage stub All the tests go back to a soothing green and we can turn our attention to the duplicated logic we just introduced in the second test. In particular both tests simulates sending a request with a body. We can simplify the tests considerably by extracting this logic into the setup. Listing 14.19 shows the updated tests. Listing 14.19 Cleaning up post tests function controllerSetUp . this.sendRequest function data var str encodeURI JSON.stringify data this.req.emit data str.substring 0 str.length 2 this.req.emit data str.substring str.length 2 this.req.emit end testCase exports chatRoomController.post . should parse request body as JSON function test var data data user cjno message hi JSON.parse stub data this.controller.post this.sendRequest data test.equals JSON.parse.args 0 JSON.stringify data test.done . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark. From the Library of WoweBook.Com 354 Server-Side JavaScript with Node.js The cleaned up tests certainly are a lot easier to follow and with the sendRequest helper method writing new tests that make requests will be easier as well. All tests pass and we can move on. 14.2.4.3 Malicious Data Notice that we are currently accepting messages completely unfiltered. This can lead to all kinds of scary situations for instance consider the effects of the request in Listing 14.20 Listing 14.20 Malicious request topic message data user cjno message script window.location http hacked script Before deploying an application like the one we are currently building we should take care to not blindly accept any end user .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.