Unit test hangs because Sinon stub doesn't work
See original GitHub issueDescribe 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:
- 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
}
- Run
npm run test:unit
Expected behavior Test should run fine
Screenshots
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@farisT referring directly to the module is ok.
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 ?