Skip to content

Commit 0b3a2c3

Browse files
authored
fix: test asserts to strict asserts (fastify#5815)
1 parent 9b63607 commit 0b3a2c3

8 files changed

+15
-18
lines changed

test/allow-unsafe-regex.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ test('allow unsafe regex allow unsafe', (t, done) => {
112112
}, (err, response, body) => {
113113
t.assert.ifError(err)
114114
t.assert.strictEqual(response.statusCode, 200)
115-
t.assert.deepEqual(JSON.parse(body), {
115+
t.assert.deepStrictEqual(JSON.parse(body), {
116116
foo: '1234'
117117
})
118118
done()

test/buffer.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test('Buffer test', async t => {
2525

2626
t.assert.ifError(response.error)
2727
t.assert.strictEqual(response.statusCode, 200)
28-
t.assert.deepEqual(response.payload.toString(), '{"hello":"world"}')
28+
t.assert.deepStrictEqual(response.payload.toString(), '{"hello":"world"}')
2929
})
3030

3131
await test('should return 400 if the body is empty', async t => {
@@ -42,7 +42,7 @@ test('Buffer test', async t => {
4242

4343
t.assert.ifError(response.error)
4444
t.assert.strictEqual(response.statusCode, 400)
45-
t.assert.deepEqual(JSON.parse(response.payload.toString()), {
45+
t.assert.deepStrictEqual(JSON.parse(response.payload.toString()), {
4646
error: 'Bad Request',
4747
code: 'FST_ERR_CTP_EMPTY_JSON_BODY',
4848
message: 'Body cannot be empty when content-type is set to \'application/json\'',

test/case-insensitive.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test('case insensitive', (t, done) => {
2525
}, (err, response, body) => {
2626
t.assert.ifError(err)
2727
t.assert.strictEqual(response.statusCode, 200)
28-
t.assert.deepEqual(JSON.parse(body), {
28+
t.assert.deepStrictEqual(JSON.parse(body), {
2929
hello: 'world'
3030
})
3131
done()
@@ -54,7 +54,7 @@ test('case insensitive inject', (t, done) => {
5454
}, (err, response) => {
5555
t.assert.ifError(err)
5656
t.assert.strictEqual(response.statusCode, 200)
57-
t.assert.deepEqual(JSON.parse(response.payload), {
57+
t.assert.deepStrictEqual(JSON.parse(response.payload), {
5858
hello: 'world'
5959
})
6060
done()
@@ -84,7 +84,7 @@ test('case insensitive (parametric)', (t, done) => {
8484
}, (err, response, body) => {
8585
t.assert.ifError(err)
8686
t.assert.strictEqual(response.statusCode, 200)
87-
t.assert.deepEqual(JSON.parse(body), {
87+
t.assert.deepStrictEqual(JSON.parse(body), {
8888
hello: 'world'
8989
})
9090
done()
@@ -114,7 +114,7 @@ test('case insensitive (wildcard)', (t, done) => {
114114
}, (err, response, body) => {
115115
t.assert.ifError(err)
116116
t.assert.strictEqual(response.statusCode, 200)
117-
t.assert.deepEqual(JSON.parse(body), {
117+
t.assert.deepStrictEqual(JSON.parse(body), {
118118
hello: 'world'
119119
})
120120
done()

test/check.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ const options = {
7272
}
7373

7474
const handler = (request, reply) => {
75-
console.log('in handler')
7675
if (request.body.id === '400') {
7776
return reply.status(400).send({
7877
statusCode: 400,
@@ -125,7 +124,7 @@ test('serialize the response for a Bad Request error, as defined on the schema',
125124
}, (err, response, body) => {
126125
t.assert.ifError(err)
127126
t.assert.strictEqual(response.statusCode, 400)
128-
t.assert.deepEqual(body, {
127+
t.assert.deepStrictEqual(body, {
129128
statusCode: 400,
130129
error: 'Bad Request',
131130
message: 'body must be object'

test/conditional-pino.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test("pino is require'd if logger is passed", t => {
2121
logger: true
2222
})
2323

24-
t.assert.notEqual(require.cache[require.resolve('pino')], undefined)
24+
t.assert.notStrictEqual(require.cache[require.resolve('pino')], undefined)
2525
})
2626

2727
test("pino is require'd if loggerInstance is passed", t => {
@@ -43,5 +43,5 @@ test("pino is require'd if loggerInstance is passed", t => {
4343
loggerInstance
4444
})
4545

46-
t.assert.notEqual(require.cache[require.resolve('pino')], undefined)
46+
t.assert.notStrictEqual(require.cache[require.resolve('pino')], undefined)
4747
})

test/http-methods/head.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ test('shorthand - should set get and head route in the same api call', t => {
122122

123123
t.assert.ok(true)
124124
} catch (e) {
125-
console.log(e)
126125
t.assert.fail()
127126
}
128127
})
@@ -147,7 +146,6 @@ test('shorthand - head, querystring schema', t => {
147146
})
148147
t.assert.ok(true)
149148
} catch (e) {
150-
console.log(e)
151149
t.assert.fail()
152150
}
153151
})
@@ -160,7 +158,6 @@ test('missing schema - head', t => {
160158
})
161159
t.assert.ok(true)
162160
} catch (e) {
163-
console.log(e)
164161
t.assert.fail()
165162
}
166163
})

test/request-timeout.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ test('requestTimeout should be set', async (t) => {
4242
t.plan(1)
4343

4444
const initialConfig = Fastify({ requestTimeout: 5000 }).initialConfig
45-
t.assert.deepEqual(initialConfig.requestTimeout, 5000)
45+
t.assert.strictEqual(initialConfig.requestTimeout, 5000)
4646
})
4747

4848
test('requestTimeout should 0', async (t) => {
4949
t.plan(1)
5050

5151
const initialConfig = Fastify().initialConfig
52-
t.assert.deepEqual(initialConfig.requestTimeout, 0)
52+
t.assert.strictEqual(initialConfig.requestTimeout, 0)
5353
})

test/route.3.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const joi = require('joi')
55
const Fastify = require('..')
66

77
test('does not mutate joi schemas', (t, done) => {
8-
t.plan(4)
8+
t.plan(5)
99

1010
const fastify = Fastify()
1111
function validatorCompiler ({ schema, method, url, httpPart }) {
@@ -31,7 +31,8 @@ test('does not mutate joi schemas', (t, done) => {
3131
params: { an_id: joi.number() }
3232
},
3333
handler (req, res) {
34-
t.assert.deepEqual(req.params, { an_id: 42 })
34+
t.assert.strictEqual(Object.keys(req.params).length, 1)
35+
t.assert.strictEqual(req.params.an_id, '42')
3536
res.send({ hello: 'world' })
3637
}
3738
})

0 commit comments

Comments
 (0)