sinonjs / formatio

The cheesy object formatter
https://sinonjs.github.io/formatio/
Other
36 stars 11 forks source link

toString might crash #25

Closed tbiesemann closed 3 years ago

tbiesemann commented 5 years ago

Calling sinon.assert.calledWith fails, if the stub was called with an object having a toString method which throws.

How to reproduce

it('shall reproduce formatio bug', function () {
    const poison = {
        toString: () => {
            throw new Error("Boom");
        }
    };

    const myStub = sinon.stub();
    myStub(poison);

    sinon.assert.calledWith(myStub, "42");
});

Expectation is to see a sinon error message like "expected stub to be called with..." instead of a formatio error.

I think a try/catch and swallow the error should be sufficient.

mroderick commented 5 years ago

Edit: enable syntax highlighting

mroderick commented 3 years ago

This package has been deprecated in favour of using util.inspet in the Sinon projects