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.

sinon_1.stub is not a function

See original GitHub issue

Checklist

  • 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.

  1. Used yarn add -D aws-sdk-client-mock to install the package to our project
  2. Created a simple test to try out the mock functionality.
  3. When running the test with const sqsMock = mockClient(SQSClient), encountered the error TypeError: 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:

aws-sdk-client-mock-wrong-import

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:closed
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
m-radzikowskicommented, Sep 30, 2021

Ok, glad you solved it!

2reactions
kylebroomfieldvariantcommented, Sep 30, 2021

The issue was with our jest.config.js. Apparently the line moduleDirectories: ['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!

Read more comments on GitHub >

github_iconTop 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 >

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