Created
June 28, 2015 19:36
-
-
Save mlenkeit/a6fa3960967b3fa6a165 to your computer and use it in GitHub Desktop.
Package collision of mock-fs and body-parser
This file contains 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
var bodyParser = require('body-parser'); | |
var express = require('express'); | |
var request = require('supertest'); | |
var fs = require('mock-fs'); | |
var app = express(); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.post('/bookmarks', function(req, res) { | |
if (req.body.url && req.body.tags) { | |
return res.sendStatus(201); | |
} else { | |
return res.sendStatus(400); | |
} | |
}); | |
describe('testing a simple application', function() { | |
beforeEach(function() { | |
fs({'C:/somedir': {'file.txt': 'hello'}}); | |
}); | |
afterEach(function() { | |
fs.restore(); | |
}); | |
it('should succeed', function(done) { | |
var payload = { | |
url: 'http://some-url.com', | |
tags: '#tags #tag' | |
}; | |
request(app) | |
.post('/bookmarks') | |
.type('form') | |
.send(payload) | |
.expect(201) | |
.end(done); | |
}); | |
it('should fail', function(done) { | |
request(app) | |
.post('/bookmarks') | |
.type('form') | |
.send({}) | |
.expect(400) | |
.end(done); | |
}); | |
}); |
This file contains 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
{ | |
"name": "tmp-code-sample", | |
"version": "0.0.1", | |
"private": true, | |
"description": "Package collision of mock-fs and body-parser", | |
"scripts": { | |
"test": "mocha *.js" | |
}, | |
"author": "Maximilian Lenkeit <maximilian.lenkeit@gmail.com>", | |
"license": "MIT", | |
"dependencies": { | |
"body-parser": "1.8.1", | |
"express": "^4.13.0" | |
}, | |
"devDependencies": { | |
"chai": "^3.0.0", | |
"mocha": "^2.2.5", | |
"mock-fs": "^3.0.0", | |
"supertest": "^1.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment