Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stubbing this library doesn't work #209

Open
Labels
type: bugcode to address defects in shipped code
@sadir

Description

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /