Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type check on array of numbers fails #11

Closed
blenderer opened this issue Mar 10, 2015 · 4 comments
Closed

Type check on array of numbers fails #11

blenderer opened this issue Mar 10, 2015 · 4 comments

Comments

@blenderer
Copy link

Sorry about the issue#10, accidentally closed it!

var chai = require('chai');
require('chai-things');

chai.should();

var numArray = [1,2,3,4,9882];

describe('array', function () {
    describe('elements', function () {
        it('should all be numbers', function () {
            return numArray.should.all.be.a('number');
        });
    });
    describe('first element', function () {
        it('should be a number', function () {
            return numArray[3].should.be.a('number');
        });
    });
});

Mocha run results:

array
  elements
    1) should all be numbers
  first element
    ✓ should be a number 


1 passing (9ms)
1 failing

1) array elements should all be numbers:
   AssertionError: expected [ 1, 2, 3, 4, 9882 ] to be a number
@RubenVerborgh
Copy link
Collaborator

Unfortunately, using Chai-Thing with a property function is not possible at the moment, and I'm unsure whether it can be fixed easily with the current Chai design. See #4, #9, and https://github.com/RubenVerborgh/Chai-Things#known-issues.

@blenderer
Copy link
Author

What's the difference between using:
.should.all.match(/.*/);
and
.should.all.be.a('number')
?

@RubenVerborgh
Copy link
Collaborator

That works, because the test is executed on the array, not on the elements, and (the stringified version of) the array coincidentally also matches /.*/. It would not work with /^\d+$/.

@blenderer
Copy link
Author

Makes sense. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants