forwardemail / forwardemail/supertest

Function toString() results in weird default arguments

Open
#528 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
14.4k
Forks
782
PR merge metrics
No merged PRs in 30d

Description

Using the following test

```js
request(app)
.get('/data/0/1/0/1')
.expect(200)
.expect('Cache-Control', 'private, no-store')
.expect('Content-Type', /json/)
.end((err, res) => {
t.error(err, 'no error')
t.ok(res.body, 'with a body')
t.equal(res.body.length, 172837, 'of the correct length')
t.end()
})
```

I had to add the commented line to this function
```js
const getArgumentNames = _func => {
const funcString = _func
.toString()
.replace(/=\([^)]*\)/g, '') // remove default args caused by test harness

const es6check = funcString.split('=>')
if (es6check.length > 1 && !es6check[0].includes('(')) {
return [es6check[0].trim()]
}

return funcString
.split(')').shift()
.split('(').pop()
.split(',')
.map(name => name.split('=').shift().trim())
}
```

In order the make the test pass. For some reason the default arguments in the stringified function went from simple `a = b` format to `a=('foobar', b)`. This doesn't happen outside of supertest.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.