I want to check if something is a function with Chai.should. So I did
typeof(barfoo).should.equals('function')
DEMO
This results in
AssertionError: expected [Function] to equal 'function'
at Context.<anonymous> (:73:31)
Can someone explain to me why this doesn't work, because if I simply do
typeof(barfoo)
I get a string function
. Although I've solved this now with instanceOf
but I really want to understand this
Running this command instructs Mocha to attach a special run() callback function to the global context. Calling the run() function instructs it to run all the test suites that have been described. Therefore, run() can be called after the asynchronous operation is completed to run the tests.
Chai is an assertion library that is mostly used alongside Mocha. It can be used both as a BDD / TDD assertion library for NodeJS and can be paired with any JavaScript testing framework. It has several interfaces that a developer can choose from and looks much like writing tests in English sentences.
notify(done) is hanging directly off of . should , instead of appearing after a promise assertion. This indicates to Chai as Promised that it should pass fulfillment or rejection directly through to the testing framework.
Note expect and should uses chainable language to construct assertions, but they differ in the way an assertion is initially constructed. In the case of should , there are also some caveats and additional tools to overcome the caveats. var expect = require('chai').
Here is how you can check if barfoo
is a function:
barfoo.should.be.a('function');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With