sinon_1.stub is not a function
See original GitHub issueChecklist
- I have read Caveats documentation and didn’t find a solution for this problem there.
Bug description
Have project setup to use Jest with ts-jest preset.
- Used
yarn add -D aws-sdk-client-mock
to install the package to our project - Created a simple test to try out the mock functionality.
- When running the test with
const sqsMock = mockClient(SQSClient)
, encountered the errorTypeError: sinon_1.stub is not a function
Navigating to the implementation of mockClient, the import shows that stub
is being pulled in from sinon.ts
in the aws-sdk-client-mock package itself instead of from sinon installed in node_modules, so an error is thrown. See reference:
The test was very simply:
import { SQSClient } from "@aws-sdk/client-sqs";
import { mockClient } from "aws-sdk-client-mock";
describe('Simple Test', () => {
const sqsMock = mockClient(SQSClient);
it('should exist', () => {
expect(true).toBeTruthy();
});
});
This was tried in two different projects (both using yarn) and on several different computers, all encountered the same issue.
Environment
- Node version: 16.8
- Typescript version: 4.3.5
- AWS SDK v3 Client mock version: 0.5.5
- AWS JS SDK libs and versions: @aws-sdk/client-sqs v3.31.0
- Yarn 1.22.10
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
sinon stub not replacing function. - Stack Overflow
You have a couple of problems here. The first is that you're calling test_stub.restore() immediately after creating the stub, which causes ...
Read more >Why isn't my Stub working (Using Sinon Stubs — part II)
The problem is that when funcB calls funcA it calls it directly, not through the exported module functions. funcA, funcB,
Read more >Stubs - Sinon.JS
Test stubs are functions (spies) with pre-programmed behavior. They support the full test spy API in addition to methods which can be used...
Read more >Original function called even when stubbing wiht sinon.stub ...
Hi everyone, I'm playing around with sinon to get familiar with how stubbing works, and I came across this scenario (which I'm not...
Read more >How to Use the Sinon stub() Function - Mastering JS
The sinon.stub() substitutes the real function and returns a stub object that you can configure using methods like callsFake() .
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
Ok, glad you solved it!
The issue was with our
jest.config.js
. Apparently the linemoduleDirectories: ['node_modules', './'],
is what causes the error. I copied the config with that line to the mock project and the test failed. Removing that line everything works as intended. I will close this issue. Thanks for the help!