Skip to content

Commit

Permalink
test:add tests to ensure objects are not modified
Browse files Browse the repository at this point in the history
  • Loading branch information
pranaygp committed Apr 12, 2024
1 parent 139fdf2 commit ca12cd5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tests/got/test_reply_body.js
Expand Up @@ -116,20 +116,20 @@ describe('`reply()` body', () => {
scope.done()
})

it('does not modify the original used for response', async () => {
const patchBody = { id: 1234 }
it('does not modify the object used for response', async () => {
const patchBody = { number: 1234 }
const form = new FormData()
form.append('number', 1234)

const scope = nock('http://example.test')
.patch('/', patchBody)
.reply(200, patchBody)

const { statusCode, headers, body } = await got.patch(
'http://example.test/',
{ body: JSON.stringify(patchBody) },
)
await got.patch('http://example.test/', {
form,
})

expect(statusCode).to.equal(200)
expect(headers).to.include({ 'content-type': 'application/json' })
expect(body).to.be.a('string').and.equal(JSON.stringify(patchBody))
expect(patchBody.number).to.be.a('number').and.equal(1234)
scope.done()
})
})
Expand Down
12 changes: 12 additions & 0 deletions tests/test_common.js
Expand Up @@ -71,6 +71,18 @@ describe('Body Match', () => {
const result = matchBody({}, { number: 1 }, '{"number": "1"}')
expect(result).to.equal(false)
})

it('should not modify the original spec object', () => {
const spec = { number: 1 }
matchBody(
{
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
},
spec,
'',
)
expect(spec).to.deep.equal({ number: 1 })
})
})
})

Expand Down

0 comments on commit ca12cd5

Please sign in to comment.