Skip to content

Check received calls #23

Description

@thrixton

Thanks for the library, it's great.

I've mimicked a method and now I'm trying to verify that it's been called, however, every time I call received(), it executes the method instead.

Is my understanding incorrect that it should just verify that the method has been executed the relevant number of times?

    const resultMock = Substitute.for<IResultService>();
    resultMock.objectResult(Arg.all()).mimicks((o, n, cb) => {
      // tslint:disable-next-line: no-unused-expression
      expect(o).to.be.instanceOf(ErrorResult);
      const eResult = o as ErrorResult;
      expect(eResult.validationErrors.length).to.equal(1);
    });

    container.unbind(TYPES.ResultService);
    container.bind<IResultService>(TYPES.ResultService).toConstantValue(resultMock);

    const service = container.get<IValidationService>(TYPES.ValidationService);

    const cbMock = Substitute.for<Callback>();
    // tslint:disable-next-line: no-unused-expression
    expect(service.handleValidationErrors(error, cbMock)).to.be.true;

    resultMock.received(1).objectResult(Arg.any(), Arg.any(), cbMock);
    // ^^^^ this results in another call to my mimicked function above

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