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

Deep expect anonymous function #324

Closed
EtienneLem opened this issue Dec 11, 2014 · 3 comments
Closed

Deep expect anonymous function #324

EtienneLem opened this issue Dec 11, 2014 · 3 comments

Comments

@EtienneLem
Copy link

Is there any way to deeply expect an anonymous function? i.e. Jasmine has jasmine.any(Function)

o = { foo: 'bar', baz: function() {  } }

// Chai (with Mocha)
expect(o).to.deep.equal({
  foo: 'bar',
  baz: Function
})

// Jasmine
expect(o).toEqual({
  foo: 'bar',
  baz: jasmine.any(Function)
})

I know about expect(o).to.have.property('baz').that.is.a('function'), but it can be a little bit more painful to deal with when the object has more keys.

@keithamus
Copy link
Member

@EtienneLem thanks for the issue! We discussed matchers a long while ago, over in #97 - but the discussion hasn't moved on much since then. It'd be a big feature to add in Chai, but we could potentially make it very powerful.

Personally I'd like to see some kind of syntax that ties into assertions, like:

// Chai (with Mocha)
expect(o).to.deep.equal({
  foo: 'bar',
  baz: chai.matched.to.be.a('function').and.have.length(2)
});

It would only really be used for deep equals as far as I can see though - so potentially lots of effort for limited scope.

@emmenko
Copy link

emmenko commented May 4, 2015

Any news on this?

@keithamus
Copy link
Member

Closing this for a more focussed discussion in #644

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

3 participants