Node.js的HTTP模擬和預期測試庫:Nock
Nock 是一個Node.js 平臺的 HTTP 模擬和預期測試庫 。可用于在隔離的情況下測試執行HTTP請求模塊。
For instance, if a module performs HTTP requests to a CouchDB server or makes HTTP requests to the Amazon API, you can test that module in isolation.
示例代碼:
var nock = require('nock'); var couchdb = nock('http://myapp.iriscouch.com') .get('/users/1') .reply(200, { _id: '123ABC', _rev: '946B7D1C', username: 'pgte', email: 'pedro.teixeira@gmail.com' });
This setup says that we will intercept every HTTP call tohttp://myapp.iriscouch.com.
It will intercept an HTTP GET request to '/users/1' and reply with a status 200, and the body will contain a user representation in JSON.
項目主頁:http://www.baiduhome.net/lib/view/home/1425977756388
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!