Skip to content

All functions shares the same state #51

@renatomariscal

Description

@renatomariscal

Hi, I have the following test:

interface Calculator {
    add(a: number, b: number): number;
    subtract(a: number, b: number): number;
    divide(a: number, b: number): number;
    isEnabled: boolean;
}

describe('calculator', () => {
    it('rejects non-called function', () => {
        const calculator = Substitute.for<Calculator>();
        calculator.add(1,2).returns(3);

        console.log(calculator.add(1,2));

        calculator.received().add(1,2);
        calculator.received().divide(1,2);
    });
});

Running on:

node       v10.7.0
ts-jest    24.0.2
ts-node    8.2.0
typescript 3.5.1
@fluffy-spoon/substitute 1.88.0

add and divide seems to be sharing the state, in that specific test I expected to get an error that divide wasn't called, but it passed.

If I change it to:

        calculator.add(1,2).returns(3);

        console.log(calculator.add(1,2));

        calculator.received().divide(4,2);

I get the error:

    Expected 1 or more calls to the method add with arguments [4, 2], but received none of such calls.
    All calls received to method add:
    -> call with arguments [1, 2]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions