Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calledWith needs assertion callback to equal values #1

Open
victor-shelepen opened this issue Jan 10, 2020 · 0 comments
Open

calledWith needs assertion callback to equal values #1

victor-shelepen opened this issue Jan 10, 2020 · 0 comments

Comments

@victor-shelepen
Copy link

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
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant