API TESTING having issues with the delete client method

Hello, I’m testing my api whit the Adonis default test framework. Everything is working great but when I try to use the client.delete method to simulate a delete request I get the following message: TypeError: client.delete is not a function.

test(‘it_should_be_able_to_destroy_a_project’, async ({client}) => {
const {user} = await userFactory()
const {project} = await projectFactory()

const res = await client
.delete(users/${user.id}/projects/${project.id})
.loginVia(user, ‘jwt’)
.end()

res.assertStatus(200)
res.assertText(‘delete’)
})

1 Like

Hey @Mc-fly82! :wave:

Have you defined the Test/ApiClient trait in your test case?

thank you for the quick response.
Yes has the guide suggested. My “post”, “get”, and “put” methods work fine.
here are my traits.

trait (‘Test/ApiClient’)
trait (‘DatabaseTransactions’)
treat (‘Auth/Client’)

Right now I work around this issue by doing a GET request on the endpoint and appending /delete to it.

Glad to hear about any further updates.

test(‘it should be able to destroy a project’, async ({client}) => {
  const {user} = await userFactory()
  const {project} = await projectFactory()

  const res = await client
    .delete( `users/${user.id}/projects/${project.id}` )
    .loginVia(user)
    .end()

  res.assertStatus(200)
  res.assertText(‘delete’)
})

(just made your code readable, to help getting answers)

Could you create a repository to reproduce the issue? Your code should work fine.

Ok, I figure out the issue by debugging the code.
If found a typo in the:
‘node_modules/@adonisjs/lucid/src/Lucid/Hooks/index. js’
This path is normally protected by my idea.
I included @adonisjs in the project files for reference lookup.
My ide taged on ‘.spec.js’ on the delete string in the ‘this. events’ array bellow.
I was creating some ‘.spec.js’ template in my idea before this happened.
can’t really tell how.

node_modules/@adonisjs/lucid/src/Lucid/Hooks/index.js:13:64

*/
class Hooks {
constructor () {

this._events = ['create', 'update', 'delete.spec.js', 'restore', 'find', 'fetch', 'paginate']

 /**

resolved