Skip to content

Instantly share code, notes, and snippets.

@joelmukuthu
Last active November 17, 2016 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelmukuthu/cb1b8fa76cfe2f90a4add0b14b7be7d3 to your computer and use it in GitHub Desktop.
Save joelmukuthu/cb1b8fa76cfe2f90a4add0b14b7be7d3 to your computer and use it in GitHub Desktop.
var httpception = require('httpception');
var got = require('got');
var assert = require('assert');
describe('the thing', function () {
before(function() {
httpception({
request: 'GET http://example.com/foobar',
response: {
headers: {
'Content-Type': 'text/plain'
},
body: 'the text'
}
});
});
it('GETs it', function () {
return got('example.com/foobar')
.then(response => assert.equal(response.body, 'the text'));
});
describe('POSTs it', function () {
before(function () {
httpception({
request: 'POST http://example.com/foobar',
response: 201
});
});
it('right', function () {
return got.post('example.com/foobar')
.then(response => assert.equal(response.statusCode, 201));
});
it('but still GETs it', function () {
return got('example.com/foobar')
.then(response => assert.equal(response.body, 'the text'));
});
it('and can also PUT it', function () {
httpception({
request: 'PUT http://example.com/foobar',
response: 202
});
return got.put('example.com/foobar')
.then(response => assert.equal(response.statusCode, 202));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment