chai-things icon indicating copy to clipboard operation
chai-things copied to clipboard

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

Open hellboy81 opened this issue 9 years ago • 2 comments

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

hellboy81 avatar Jul 16 '15 07:07 hellboy81

+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

victorherraiz avatar Aug 18 '15 11:08 victorherraiz

With unexpected.js it should work as follows:

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

hellboy81 avatar Aug 26 '15 16:08 hellboy81