How to say “any_instance” “should_receive” any number of times in RSpec

Here’s a better answer that avoids having to override the :new method: save_count = 0 <Model>.any_instance.stub(:save) do |arg| # The evaluation context is the rspec group instance, # arg are the arguments to the function. I can’t see a # way to get the actual <Model> instance 🙁 save_count+=1 end …. run the test here … Read more

Overriding `tsconfig.json` for ts-node in mocha

You need to set the configuration through the TS_NODE_COMPILER_OPTIONS environment variable Example code on an unix machine: TS_NODE_COMPILER_OPTIONS='{“module”:”commonjs”}’ \ mocha –require ts-node/register ‘test/**/*.spec.{ts,tsx}’ Explanation extracted from the repository documentation CLI and Programmatic Options Environment variable denoted in parentheses. -T, –transpile-only Use TypeScript’s faster transpileModule (TS_NODE_TRANSPILE_ONLY, default: false) -I, –ignore [pattern] Override the path patterns to … Read more

In node package.json, invoke script from another script with extra parameter, in this case add mocha watcher

This can be done in npm@2.1.17. You don’t specify your OS and the version of npm that you are using, but unless you have done something to update it, you are probably running npm@1.4.28 which does not support the syntax below. On Linux or OSX you can update npm with sudo npm install -g npm@latest. … Read more

Mocha not exiting after test

I know it is a bit late to answer this, but I was facing a similar problem and saw your post. In mocha 4.0.0, they changed the behavior of tests on finalization.From here: If the mocha process is still alive after your tests seem “done”, then your tests have scheduled something to happen (asynchronously) and … Read more

Is there a way to get Chai working with asynchronous Mocha tests?

Your asynchronous test generates an exception, on failed expect()ations, that cannot be captured by it() because the exception is thrown outside of it()‘s scope. The captured exception that you see displayed is captured using process.on(‘uncaughtException’) under node or using window.onerror() in the browser. To fix this issue, you need to capture the exception within the … Read more

Mocha beforeEach vs before execution

While this answer just shows the documentation notes again, and had some comments to try to help show the difference, the answer below by @tomasz-wszelaki should be refered to. Mocha’s test runner explains this functionality the best in the Hooks section of the Mocha Test Runner. From the Hooks section: describe(‘hooks’, function() { before(function() { … Read more

What’s the right way to enable the node debugger with mocha’s –debug-brk switch?

UPDATE As of mocha 7.0.0, –debug-brk has been removed in favor of –inspect-brk Using a recent version of nodejs (>=v6.3.0) and mocha (>=3.1.0), you can use V8 inspector integration. V8 Inspector integration allows attaching Chrome DevTools to Node.js instances for debugging and profiling Usage –inspect activates V8 inspector integration, and –debug-brk adds a breakpoint at … Read more

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