Last active
December 29, 2015 08:49
-
-
Save yixizhang/7645566 to your computer and use it in GitHub Desktop.
nock sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nock = require 'nock' | |
quest = require 'quest' | |
# chaining | |
scope = nock('http://url.ly') | |
.filteringRequestBody (path) -> | |
if path == '*' | |
return '-' | |
else | |
return '*' | |
.post('/', '*') | |
.reply(404) | |
.post('/', '-') | |
.reply(200) | |
quest {uri: 'http://url.ly', method: 'POST', body: '*'}, (err, resp, body) -> | |
console.log resp.statusCode | |
quest {uri: 'http://url.ly', method: 'POST', body: '-'}, (err, resp, body) -> | |
console.log resp.statusCode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment