2

My nodejs server responds with an object containing an array of objects like this:

{
  error: false
  message: "get dispatchers successful"
  data: [1]
  0: {
    id: 1
    first_name: "Brenth Andrew J."
    last_name: "Miras"
    contact_number: null
    email: "brenthmiras2@gmail.com"
    address: null
    image: null
    password: "bajmiras"
    created: "2014-09-12T10:24:06.000Z"
  }
}

Now i want to test for the types of the attributes of 'data' for all element of array data.

my frisby test looks like this:

//expect these types of response
.expectJSONTypes('*', {
  error: Boolean,
  message: String,
  data: {
    id: Number,
    first_name: String,
    last_name: String,
    contact_number: String,
    email: String,
    address: String,
    image: String,
    password: String,
    created: String
  }
})

and i get this error:

TypeError: Expected '*' to be Array (got 'object' from JSON response)

How am I supposed to do that?

Kara Brightwell
  • 2,529
  • 1
  • 21
  • 29
user3631341
  • 515
  • 2
  • 5
  • 16

2 Answers2

3

Remove your first argument '*' because that means you're expecting an array,

when the response is an array it would compare all the itmes in the array, so you can use index '0' intead of '*'

dpineda
  • 2,401
  • 27
  • 25
3

Each segment of the path is split by . as you can find in the source code of frisby/lib/frisby.js

  _.each(path.split('.'), function(segment) {

so to do your test will be something like:

.expectJSON('data.0', {last_name: "Miras"})
.expectJSONTypes('data.0', {
    id: Number,
    first_name: String
..
bolila
  • 58
  • 3