question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unit test hangs because Sinon stub doesn't work

See original GitHub issue

Describe the bug When I run npm run test:unit the test hangs with Inquirer prompt and Sinon stub doesn’t get used

To Reproduce Steps to reproduce the behavior:

  1. add .mocharc.js with below code in it to run with new Mocha version and node v14.14.0
'use strict';

module.exports = {
  diff: true,
  extension: ['ts'],
  reporter: 'spec',
  recursive: true,
  require: ['ts-node/register', 'test/mocha.require.ts'],
  spec: 'src/**/*.spec.ts',
  watch: true
}
  1. Run npm run test:unit

Expected behavior Test should run fine

Screenshots Screen Shot 2020-10-19 at 11 22 59 pm

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jeroenouwcommented, Oct 21, 2020

@farisT referring directly to the module is ok.

1reaction
farisTcommented, Oct 21, 2020

The issue is because of the transpiling of the modules using import/export. Refer to this thread https://github.com/sinonjs/sinon/issues/1711. Therefore when you refer to the index.ts it cannot find what to stub. The solution is either referring to the module directly in the stubbed tests eg. import * as actions from './actions/github.actions'; Or using something like proxyquire as I mentioned previously. What do you think @jeroenouw ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to handle sinon.stub().throws() in unit test by Sinon JS
Had a similar issue with throws and Promises on a mock.I'm assuming the API is the same. Try using rejects instead of throws...
Read more >
Best Practices for Spies, Stubs and Mocks in Sinon.js
Learn about differences between spies, stubs and mocks, when and how to use them, and get a set of best practices to help...
Read more >
Simple stub fails for ES6 import #1711 - sinonjs/sinon - GitHub
The test should pass. What actually happens. The method is never mocked. It still returns 'fail' even with the direct stub above it....
Read more >
Using Stubs for Testing in JavaScript with Sinon.js - Stack Abuse
While making requests to external services in a test, you can run into these problems: Failing tests because of network connectivity errors ......
Read more >
Stub (Using sinon) | Mocha - Javascript unit testing framework
This is the 5th video tutorial of this web series on Mocha - Javascript unit testing framework. In the previous video tutorial, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found