The difference between assert.equal and assert.deepEqual in Javascript testing with Mocha?

Why do arrays not compare the way other values do (e.g. 1==1) Numbers, strings, booleans, null, and undefined are values, and are compared as you might expect. 1 == 1, ‘a’ == ‘a’, and so on. The difference between === and == in the case of values is that == will attempt to perform type … Read more

Testing javascript with Mocha – how can I use console.log to debug a test?

What Mocha options are you using? Maybe it is something to do with reporter (-R) or ui (-ui) being used? console.log(msg); works fine during my test runs, though sometimes mixed in a little goofy. Presumably due to the async nature of the test run. Here are the options (mocha.opts) I’m using: –require should -R spec … Read more

eslint should be listed in the project’s dependencies, not devDependencies

Solved it with adding this to my .eslintrc: “import/no-extraneous-dependencies”: [“error”, {“devDependencies”: true}] [no-extraneous-dependencies] Add exceptions? #422 Based on this user’s reply: you could set the option devDependencies: true in an .eslintrc in your test folder: rules: import/no-extraneous-dependencies: [error, { devDependencies: true }] Then you’ll get reports of any packages referenced that are not included dependencies … Read more

Unit testing of private functions with Mocha and Node.js

Check out the rewire module. It allows you to get (and manipulate) private variables and functions within a module. So in your case the usage would be something like: var rewire = require(‘rewire’), foobar = rewire(‘./foobar’); // Bring your module in with rewire describe(“private_foobar1”, function() { // Use the special ‘__get__’ accessor to get your … Read more

Cleaning up sinon stubs easily

Sinon provides this functionality through the use of Sandboxes, which can be used a couple ways: // manually create and restore the sandbox var sandbox; beforeEach(function () { sandbox = sinon.sandbox.create(); }); afterEach(function () { sandbox.restore(); }); it(‘should restore all mocks stubs and spies between tests’, function() { sandbox.stub(some, ‘method’); // note the use of … Read more

Getting a UnhandledPromiseRejectionWarning when testing using mocha/chai

The issue is caused by this: .catch((error) => { assert.isNotOk(error,’Promise error’); done(); }); If the assertion fails, it will throw an error. This error will cause done() never to get called, because the code errored out before it. That’s what causes the timeout. The “Unhandled promise rejection” is also caused by the failed assertion, because … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)