chaijs / chai-things

Chai support for assertions on array elements
http://chaijs.com/plugins/chai-things
Other
104 stars 14 forks source link

[bug] [discussion] [feature request] Asserting all array elements have the type #16

Open hellboy81 opened 9 years ago

hellboy81 commented 9 years ago

Assume

var list = ['1', '2']

This code does not works:

should.exist(list)

list.should.be.an('array') // Passed
     .with.length(2) // Passed
     .and.all.be.an('string') // Failed: expected '1' to be a string
victorherraiz commented 9 years ago

+1

var a = [{id:1}, {id:2}]; 
expect(a[0]).property("id").is.a("number"); //works
expect(a).all.property("id").is.a("number"); //fails
hellboy81 commented 9 years ago

With unexpected.js it should work as follows:

expect(list, 'to be an array whose items satisfy', expect.it('to be a string'))