Skip to content

Adding complex object to request().field() method #842

@swkang0513

Description

@swkang0513

Describe the bug

Node.js version: 18.18.2

OS version: macOS Sonoma 14.4

Description:

When adding complex object to field() method, the documentation says to use it like this. #759

.field('complex_object', '{"attribute": "value"}', {contentType: 'application/json'})

With this solution, I got an error.

Expected 1-2 arguments, but got 3.ts(2554)

@types/supertest 6.0.2
supertest 7.0.0
typescript 5.4.5

Actual behavior

await request(app)
  .post('/test')
  .field('myObject', JSON.stringify({ key1: 'key1', key2: 'key2' }), { contentType: 'application/json' })
  .attach('attachments', path.join(__dirname, 'image.png'))
  .expect(200)

Expected behavior

Test success without an error.

Code to reproduce

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions