Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECONNRESET Error When Uploading File in Jest Test Using superagent #1815

Open
nipunaram opened this issue Sep 4, 2024 · 0 comments
Open
Labels

Comments

@nipunaram
Copy link

Describe the bug

I'm encountering an econnrest error when attempting to upload a file in my Jest test using superagent. The error occurs when the attach() method is called to attach the file to the request.

Node.js version: 20.17

OS version: Windows 11 Pro

Code to reproduce

		test('should throw not found error when the question does not allow any files', async () => {
			let question = getQuestion()
			question.allowFile = false
			question.isFileRequired = false

			const mpg = pg as unknown as jest.Mock
			mpg.mockReturnValueOnce(mock(question))

			const res1 = await request({
				rolesId: UserRole.ADMIN,
			})
				.post('/questionnairee/question/1/answer/file')
				.attach('file', '__mocks__/data/files/image_1.png')   //This is where the issue is being produced
				.expect(404)

			expect(ErrorResSchema.safeParse(res1.body).success).toBeTruthy()

			question = getQuestion()
			question.allowFile = false
			question.isFileRequired = true

			mpg.mockReturnValueOnce(mock(question))

			const res2 = await request({
				rolesId: UserRole.ADMIN,
			})
				.post('/questionnairee/question/1/answer/file')
				.attach('file', '__mocks__/data/files/image_1.png')
				.expect(404)

			expect(ErrorResSchema.safeParse(res2.body).success).toBeTruthy()
		})

Checklist

  • [v] I have searched through GitHub issues for similar issues.
  • [v] I have completely read through the README and documentation.
  • [v] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.
@nipunaram nipunaram added the Bug label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant