Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stubbing this library doesn't work #209

Open
sadir opened this issue Jan 24, 2025 · 1 comment
Open

Stubbing this library doesn't work #209

sadir opened this issue Jan 24, 2025 · 1 comment
Labels
type: bug code to address defects in shipped code

Comments

@sadir
Copy link

sadir commented Jan 24, 2025

Please search other issues to make sure this bug has not already been reported. ✅

Hey team, thanks for supporting this library.

Describe the bug

If you want to stub out getStore using Sinon you'll get an error like this:

TypeError: Descriptor for property getStore is non-configurable and non-writable

E.g. in a test file like this

import sinon from "sinon";
import * as netlifyBlobs from "@netlify/blobs";
import { type Store } from "@netlify/blobs";

describe("thing", () => {
    let mockStore: Partial<Store>;
    let setStub: sinon.SinonStub;
    let getStoreStub: sinon.SinonStub;

    beforeEach(() => {
        setStub = sinon.stub().resolves();
        mockStore = {
            set: setStub,
        };
        getStoreStub = sinon.stub(netlifyBlobs, "getStore").returns(mockStore as Store);
    });
  1. Is it because getStore is exported as a const here?
  2. Why export a function as a const? I've not seen that before
  3. How do you recommend people mock / stub out your package

I can just wrap getStore in a module and mock that but it feels like a shame to introduce that complexity to my codebase.

@sadir sadir added the type: bug code to address defects in shipped code label Jan 24, 2025
@sadir
Copy link
Author

sadir commented Jan 24, 2025

Related: sinonjs/sinon#2377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

1 participant