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: "[email protected]"
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?
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
..