Refactor tests - add arrow functions

Refactor tests - move .should to the same line as arrow function
This commit is contained in:
Slobodan Stojanovic 2015-10-24 18:24:38 +02:00 committed by Jonathan Ong
parent e859c602d1
commit cc1d41f5e3
5 changed files with 17 additions and 40 deletions

View file

@ -9,9 +9,7 @@ describe('app.onerror(err)', function(){
it('should throw an error if a non-error is given', function(done){ it('should throw an error if a non-error is given', function(done){
const app = new Koa(); const app = new Koa();
(function(){ (() => app.onerror('foo')).should.throw(AssertionError, {message: 'non-error thrown: foo'});
app.onerror('foo');
}).should.throw(AssertionError, {message: 'non-error thrown: foo'});
done(); done();
}); });
@ -22,9 +20,7 @@ describe('app.onerror(err)', function(){
err.status = 404; err.status = 404;
const output = stderr.inspectSync(function(){ const output = stderr.inspectSync(() => app.onerror(err));
app.onerror(err);
});
output.should.eql([]); output.should.eql([]);
@ -36,9 +32,7 @@ describe('app.onerror(err)', function(){
app.silent = true; app.silent = true;
const err = new Error(); const err = new Error();
const output = stderr.inspectSync(function(){ const output = stderr.inspectSync(() => app.onerror(err));
app.onerror(err);
});
output.should.eql([]); output.should.eql([]);
@ -52,9 +46,7 @@ describe('app.onerror(err)', function(){
const err = new Error(); const err = new Error();
err.stack = 'Foo'; err.stack = 'Foo';
const output = stderr.inspectSync(function(){ const output = stderr.inspectSync(() => app.onerror(err));
app.onerror(err);
});
output.should.eql(['\n', ' Foo\n', '\n']); output.should.eql(['\n', ' Foo\n', '\n']);
@ -68,9 +60,7 @@ describe('app.onerror(err)', function(){
const err = new Error('mock stack null'); const err = new Error('mock stack null');
err.stack = null; err.stack = null;
const output = stderr.inspectSync(function(){ const output = stderr.inspectSync(() => app.onerror(err));
app.onerror(err);
});
output.should.eql(['\n', ' Error: mock stack null\n', '\n']); output.should.eql(['\n', ' Error: mock stack null\n', '\n']);

View file

@ -207,16 +207,12 @@ describe('app.respond', function(){
ctx.status = 200; ctx.status = 200;
res.setHeader('Content-Type', 'text/html'); res.setHeader('Content-Type', 'text/html');
res.write('Hello'); res.write('Hello');
setTimeout(function(){ setTimeout(() => res.end('Goodbye'), 0);
res.end('Goodbye');
}, 0);
}); });
let errorCaught = false; let errorCaught = false;
app.on('error', function(err){ app.on('error', err => errorCaught = err);
errorCaught = err;
});
const server = app.listen(); const server = app.listen();

View file

@ -21,9 +21,8 @@ describe('ctx.cookies.set()', function(){
.end(function(err, res){ .end(function(err, res){
if (err) return done(err); if (err) return done(err);
res.headers['set-cookie'].some(function(cookie){ res.headers['set-cookie'].some(cookie => /^name=/.test(cookie))
return /^name=/.test(cookie); .should.be.ok;
}).should.be.ok;
done(); done();
}); });
@ -68,13 +67,9 @@ describe('ctx.cookies.set()', function(){
const cookies = res.headers['set-cookie']; const cookies = res.headers['set-cookie'];
cookies.some(function(cookie){ cookies.some(cookie => /^name=/.test(cookie)).should.be.ok;
return /^name=/.test(cookie);
}).should.be.ok;
cookies.some(function(cookie){ cookies.some(cookie => /^name\.sig=/.test(cookie)).should.be.ok;
return /^name\.sig=/.test(cookie);
}).should.be.ok;
done(); done();
}); });

View file

@ -8,16 +8,12 @@ module.exports = function(req, res){
const socket = new Stream.Duplex(); const socket = new Stream.Duplex();
req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype }; req = req || { headers: {}, socket: socket, __proto__: Stream.Readable.prototype };
res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype }; res = res || { _headers: {}, socket: socket, __proto__: Stream.Writable.prototype };
res.getHeader = function(k){ return res._headers[k.toLowerCase()]; }; res.getHeader = k => res._headers[k.toLowerCase()];
res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v; }; res.setHeader = (k, v) => res._headers[k.toLowerCase()] = v;
res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()]; }; res.removeHeader = (k, v) => delete res._headers[k.toLowerCase()];
return (new Koa()).createContext(req, res); return (new Koa()).createContext(req, res);
}; };
module.exports.request = function(req, res){ module.exports.request = (req, res) => module.exports(req, res).request;
return module.exports(req, res).request;
};
module.exports.response = function(req, res){ module.exports.response = (req, res) => module.exports(req, res).response;
return module.exports(req, res).response;
};

View file

@ -39,7 +39,7 @@ describe('ctx.href', function(){
res.statusCode.should.equal(200); res.statusCode.should.equal(200);
let buf = ''; let buf = '';
res.setEncoding('utf8'); res.setEncoding('utf8');
res.on('data', function(s){ buf += s; }); res.on('data', s => buf += s);
res.on('end', function(){ res.on('end', function(){
buf.should.equal('http://example.com/foo'); buf.should.equal('http://example.com/foo');
done(); done();