Skip to content

Commit

Permalink
add test for the wrap method 🧪 ..
Browse files Browse the repository at this point in the history
  • Loading branch information
3imed-jaberi committed Apr 25, 2021
1 parent 5c141cf commit 15ccb13
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const options = {
collapseWhitespace: true
};

describe('Koa HTML Minifier', function() {
describe('when the response is HTML', function() {
describe('Koa HTML Minifier', function () {
describe('when the response is HTML', function () {
const input = '<div> <p> foo </p> </div>';
const output = '<div><p>foo</p></div>';

describe('and the body is empty', function() {
it('should not crash', function(done) {
describe('and the body is empty', function () {
it('should not crash', function (done) {
const app = new Koa();
app.use(minifier(options));
app.use(ctx => ctx.body = null);
Expand All @@ -23,8 +23,8 @@ describe('Koa HTML Minifier', function() {
});
});

describe('and the body is a string', function() {
it('should minify', function(done) {
describe('and the body is a string', function () {
it('should minify', function (done) {
const app = new Koa();
app.use(minifier(options));
app.use(ctx => ctx.body = input);
Expand All @@ -36,8 +36,8 @@ describe('Koa HTML Minifier', function() {
});
});

describe('and the body is a buffer', function() {
it('should minify', function(done) {
describe('and the body is a buffer', function () {
it('should minify', function (done) {
const app = new Koa();
app.use(minifier(options));
app.use(ctx => {
Expand All @@ -49,8 +49,8 @@ describe('Koa HTML Minifier', function() {
});
});

describe('and the body is an object', function() {
it('should not crash', function(done) {
describe('and the body is an object', function () {
it('should not crash', function (done) {
const app = new Koa();
app.use(minifier(options));
app.use(ctx => {
Expand All @@ -62,8 +62,8 @@ describe('Koa HTML Minifier', function() {
});
});

describe('and the body is a stream', function() {
it('should not minify', function(done) {
describe('and the body is a stream', function () {
it('should not minify', function (done) {
const app = new Koa();
app.use(minifier(options));
app.use(ctx => {
Expand All @@ -77,8 +77,8 @@ describe('Koa HTML Minifier', function() {
});
});

describe('when the response is not HTML', function() {
it('should do nothing', function(done) {
describe('when the response is not HTML', function () {
it('should do nothing', function (done) {
const text = 'lol < > <3';
const app = new Koa();
app.use(minifier(options));
Expand All @@ -89,4 +89,18 @@ describe('Koa HTML Minifier', function() {
request(app.listen()).get('/').expect(200).expect(text, done);
});
});

describe('and the body is an HTML, but prase error', function () {
it('should not crash', function (done) {
const app = new Koa();
app.use(minifier(options));
app.use(ctx => {
ctx.response.type = 'html';
// invalid html.
ctx.body = '<p>111<222</p>';
});

request(app.listen()).get('/').expect(500).expect(/Parse Error/, done);
});
});
});

0 comments on commit 15ccb13

Please sign in to comment.