Skip to content

calledWith needs assertion callback to equal values #1

Description

@victor-shelepen

I call an upper level function that modifies the object before passing it to the spy function. I do not
want to mock all upper level function.

Implementation.

write: async function (data) {
  await this.socket.write(Buffer.from(data))
}

Failure testing.

const uuid = generateUuid()
operator.write(uuid)
operator.socket.write.should.be.calledWith(uuid)

Temporary solution.

const calledValue = operator.socket.write.lastCall.args[0].toString()
assert.equal(uuid, calledValue)

Testing solution proposed.

const uuid = generateUuid()
operator.write(uuid)
operator.socket.write.should.be.calledWith((value) => {
  return value.toString() == uuid
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions