Sinon Stub Framework (Sinon Re-export)

1.0.4 · abandoned · verified Sun Apr 19

This package, `sinon-stub-framework`, is a minimalistic wrapper that directly re-exports the entire `sinon` library. Its primary function appears to have been to provide the `sinon` package under an alternative name, possibly for historical or specific project reasons. Currently at version 1.0.4, the package has not seen updates in approximately five years (as of early 2026), suggesting it is effectively abandoned. There is no unique functionality, API, or release cadence separate from `sinon` itself, which is a mature and actively maintained library for test spies, stubs, and mocks. Users are strongly advised to install and use `sinon` directly instead of this wrapper to ensure they receive the latest features, bug fixes, and security updates.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of Sinon stubs, showing how to replace a method's implementation, control its return values, and restore the original function after tests. This code is functionally identical to using `sinon` directly.

import { stub } from 'sinon-stub-framework';

class MyService {
  fetchData(id) {
    return Promise.resolve(`Data for ${id}`);
  }
  processData(data) {
    return data.toUpperCase();
  }
}

describe('MyService', () => {
  let myService;
  let fetchDataStub;

  beforeEach(() => {
    myService = new MyService();
    // Stub a method to control its behavior during tests
    fetchDataStub = stub(myService, 'fetchData');
  });

  afterEach(() => {
    // Restore the original method after each test
    fetchDataStub.restore();
  });

  it('should return stubbed data', async () => {
    fetchDataStub.returns(Promise.resolve('Mocked Data'));
    const result = await myService.fetchData(1);
    expect(result).toBe('Mocked Data');
    expect(fetchDataStub.calledOnceWith(1)).toBe(true);
  });

  it('should throw an error when stubbed', async () => {
    const errorMessage = 'Network Error!';
    fetchDataStub.throws(new Error(errorMessage));
    await expect(myService.fetchData(2)).rejects.toThrow(errorMessage);
    expect(fetchDataStub.calledOnceWith(2)).toBe(true);
  });

  it('should process data correctly even with stubbed dependency', () => {
    fetchDataStub.returns(Promise.resolve('raw data'));
    // Test another method that might rely on fetchData but we control its output
    const processed = myService.processData('another data'); // Assuming processData doesn't call fetchData here for simplicity
    expect(processed).toBe('ANOTHER DATA');
  });
});

view raw JSON →