Skip to content

Instantly share code, notes, and snippets.

@koresar
Last active July 23, 2017 10:39
Show Gist options
  • Save koresar/f246399b19f6de4b9786f990e18ef8e1 to your computer and use it in GitHub Desktop.
Save koresar/f246399b19f6de4b9786f990e18ef8e1 to your computer and use it in GitHub Desktop.
Fun with Stamps. Episode 17. Easy 100% unit test coverage in JS: - app2-test1.js
describe('express app setup', () => {
const http = {
createServer() {
return {on() {}, listen() {}};
}
};
const App = require('../app2').props({http});
it('should share ./public', (done) => {
const express = () => ({set() {}, use() {}});
express.static = (path) => {
if (path.endsWith('/public')) {
done();
}
};
const MockedApp = App.props({express});
MockedApp();
});
it('should not share non ./public', () => {
const express = () => ({set() {}, use() {}});
express.static = (path) => {
if (!path.endsWith('/public')) {
throw new Error('Should not share non public files');
}
};
const MockedApp = App.props({express});
MockedApp();
});
it('should set urlencoded external=false', (done) => {
const bodyParser = {
json() { return () => {}; },
urlencoded({extended}) {
if (extended !== false) {
throw new Error('urlencoded extended option must be false');
}
done();
return () => {};
}
};
const MockedApp = App.props({bodyParser});
MockedApp();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment