Jeanluca Scaljeri
Jeanluca Scaljeri

Reputation: 29129

How to match a function with chai.should

Let say that a function should return the following

{ key: 'bar',
  cb: () => {},
  ...
}

The question is now how I can validate this in a unit test. If I do for example

getFunc().should.eql({key: 'bar', cb: () => {}, ...});

it always fails because the cb value is a different function Does Chai.should have an equivalent of jasmine.any(Function) ? or how is this done with chai.should ?

Upvotes: 2

Views: 218

Answers (1)

rayners
rayners

Reputation: 539

I dug around in the chai docs and instanceOf seems to be the best candidate for an equivalent of jasmine.any(Function).

var result = getFunc();
result.cb.should.be.instanceOf(Function);
result.should.contain.all.keys(['key']);

Upvotes: 4

Related Questions