0

I'm not sure what is wrong here, but it seems to not being able to pass the test. Function returns an array, so it's an instance of an Object, right ?

This is what I got as an output from Jest:

 FAIL  src/services/database.spec.js
  ● should be able to get an item from a table by id

    expect(received).toBeInstanceOf(expected)

    Expected constructor: Object (<--- this is green)
    Received constructor: Object (<--- this is red)

      77 |   const user = await service.getById('users', 1)
      78 |
    > 79 |   expect(user).toBeInstanceOf(Object)
         |                ^
      80 |   expect(user).toHaveProperty('id')
      81 |   expect(user).toHaveProperty('email')
      82 |   expect(user).toHaveProperty('password')

I'm using a KNEX.js ORM to interact with database:

// this.orm is an instance of knex()
  async getById (table, id) {
    const item = await this.orm(table).where('id', id)

    return item[0]
  }
aspirinemaga
  • 3,753
  • 10
  • 52
  • 95

0 Answers0