Skip to content

Privatized stamp with stubs/fakes #47

Description

@MaximusHaximus

Howdy,
I'm running into some problems with stubbing methods on stamps that have been privatized. In particular, because referencing the injected method always references the PROXY function, there's no way to access the stubs properties. It'd be nice to be able to reference the stubs on their location since they are not private-ized and it's counter intuitive to not be able to access properties on the public methods. Not sure the best way to go about achieving that goal. For now I am storing my stubs in a local closure, then referencing them from their local closure variables. It'd be nicer to be able to reference the functions directly on the object. Open to any alternative composition patterns too, if there's a better way to accomplish this.

const Configure = require('@stamp/configure');
const stampit   = require('@stamp/it');
const sinon     = require('sinon');

const exampleStamp = stampit.compose(Configure)
  .methods({ myMethod() { return true; } });

const exampleStampInstance = exampleStamp();

const exampleMethodResult = exampleStampInstance.myMethod();
console.log(exampleMethodResult); // true

const myStub       = sinon.fake.returns(false);
const stubbedStamp = exampleStamp.methods({ myMethod: myStub });

const stubbedStampInstance = stubbedStamp();

const stubbedMethodResult = stubbedStampInstance.myMethod();

console.log(stubbedMethodResult); // false -- fake was called as expected (good!)
console.log('myStub.called', myStub.called); // true -- the stub logged the call

console.log('stubbedStampInstance.myMethod.called', stubbedStampInstance.myMethod.called); // undefined (should be true, not intuitive at all)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions