Skip to content

Commit 8054e78

Browse files
committed
test: various non-integer
1 parent 9a00de4 commit 8054e78

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/req.range.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,41 @@ describe('req', function(){
6464
.expect(/TypeError: size must be a non-negative integer to req\.range/);
6565
});
6666

67+
it('should throw TypeError for various invalid size types', function () {
68+
var app = express();
69+
var testCases = [
70+
{ value: 'string', label: 'string' },
71+
{ value: {}, label: 'object' },
72+
{ value: [], label: 'array' },
73+
{ value: null, label: 'null' },
74+
{ value: undefined, label: 'undefined' },
75+
{ value: 1.5, label: 'float' },
76+
{ value: NaN, label: 'NaN' },
77+
{ value: Infinity, label: 'Infinity' }
78+
];
79+
80+
app.use(function (req, res) {
81+
var type = req.query.type;
82+
var value = testCases.find(c => c.label === type).value;
83+
84+
try {
85+
req.range(value);
86+
res.send('no error');
87+
} catch (err) {
88+
res.status(500).send(err.name + ': ' + err.message);
89+
}
90+
});
91+
92+
// Run all tests in sequence
93+
return Promise.all(testCases.map(function (testCase) {
94+
return request(app)
95+
.get('/?type=' + testCase.label)
96+
.set('Range', 'bytes=0-10')
97+
.expect(500)
98+
.expect(/TypeError: size must be a non-negative integer to req\.range/);
99+
}));
100+
});
101+
67102
it('should have a .type', function (done) {
68103
var app = express()
69104

0 commit comments

Comments
 (0)