|
1 | | -var request = require('supertest') |
2 | | -var koa = require('koa') |
3 | | -var urllib = require('urllib') |
4 | | - |
5 | | -var qs = require('..') |
| 1 | +const request = require('supertest') |
| 2 | +const Koa = require('koa') |
| 3 | +const urllib = require('urllib') |
| 4 | +const convert = require('koa-convert') |
| 5 | +const qs = require('..') |
6 | 6 |
|
7 | 7 | describe('Koa Querystring', function () { |
8 | 8 | it('should work with extended mode by default', function (done) { |
9 | | - var app = qs(koa()) |
| 9 | + let app = qs(new Koa()) |
10 | 10 |
|
11 | | - app.use(function* (next) { |
| 11 | + app.use(convert(function* (next) { |
12 | 12 | try { |
13 | 13 | yield* next |
14 | 14 | } catch (err) { |
15 | 15 | console.error(err.stack) |
16 | 16 | } |
17 | | - }) |
| 17 | + })) |
18 | 18 |
|
19 | | - app.use(function* () { |
| 19 | + app.use(convert(function* () { |
20 | 20 | this.query.should.eql({ |
21 | | - a: [1, 2, 3] |
| 21 | + a: ['1', '2', '3'] |
22 | 22 | }) |
23 | 23 | this.query = { |
24 | | - a: [1, 2] |
| 24 | + a: ['1', '2'] |
25 | 25 | } |
26 | 26 | this.query.should.eql({ |
27 | | - a: [1, 2] |
| 27 | + a: ['1', '2'] |
28 | 28 | }) |
29 | 29 | this.querystring = 'a[0]=1&a[1]=2&a[2]=3' |
30 | 30 | this.query.should.eql({ |
31 | | - a: [1, 2, 3] |
| 31 | + a: ['1', '2', '3'] |
32 | 32 | }) |
33 | 33 |
|
34 | 34 | this.status = 204 |
35 | | - }) |
| 35 | + })) |
36 | 36 |
|
37 | 37 | request(app.listen()) |
38 | 38 | .get('/?a[0]=1&a[1]=2&a[2]=3') |
39 | 39 | .expect(204, done) |
40 | 40 | }) |
41 | 41 |
|
42 | 42 | describe('strict mode: array item', function () { |
43 | | - var app = qs(koa(), 'strict') |
| 43 | + let app = qs(new Koa(), 'strict') |
44 | 44 |
|
45 | | - app.use(function* () { |
| 45 | + app.use(convert(function* () { |
46 | 46 | this.body = this.query; |
47 | | - }) |
| 47 | + })) |
48 | 48 |
|
49 | | - var host |
| 49 | + let host |
50 | 50 | before(function (done) { |
51 | 51 | app.listen(0, function () { |
52 | | - host = 'http://localhost:' + this.address().port |
| 52 | + host = `http://localhost:${this.address().port}` |
53 | 53 | done() |
54 | 54 | }) |
55 | 55 | }) |
56 | 56 |
|
57 | 57 | it('should return the query params array', function (done) { |
58 | | - urllib.request(host + '/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true', { |
| 58 | + urllib.request(`${host}/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true`, { |
59 | 59 | dataType: 'json' |
60 | 60 | }, function (err, body, res) { |
61 | 61 | res.statusCode.should.equal(200) |
@@ -83,22 +83,22 @@ describe('Koa Querystring', function () { |
83 | 83 | }) |
84 | 84 |
|
85 | 85 | describe('first mode: first string item', function () { |
86 | | - var app = qs(koa(), 'first') |
| 86 | + let app = qs(new Koa(), 'first') |
87 | 87 |
|
88 | | - app.use(function* () { |
| 88 | + app.use(convert(function* () { |
89 | 89 | this.body = this.query; |
90 | | - }) |
| 90 | + })) |
91 | 91 |
|
92 | | - var host |
| 92 | + let host |
93 | 93 | before(function (done) { |
94 | 94 | app.listen(0, function () { |
95 | | - host = 'http://localhost:' + this.address().port |
| 95 | + host = `http://localhost:${this.address().port}` |
96 | 96 | done() |
97 | 97 | }) |
98 | 98 | }) |
99 | 99 |
|
100 | 100 | it('should return the first query params string', function (done) { |
101 | | - urllib.request(host + '/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true', { |
| 101 | + urllib.request(`${host}/foo?p=a,b&p=b,c&empty=&empty=&empty=&n=1&n=2&n=1&ok=true`, { |
102 | 102 | dataType: 'json' |
103 | 103 | }, function (err, body, res) { |
104 | 104 | res.statusCode.should.equal(200) |
|
0 commit comments