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

verify() is not able to verify arguments except for the last call #217

Open
subodhkarwa opened this issue Jul 5, 2021 · 1 comment
Open

Comments

@subodhkarwa
Copy link

subodhkarwa commented Jul 5, 2021

Description:

export enum Status {
    NEW = 'NEW',
    UPDATED = 'UPDATED',
    COMPLETED = 'COMPLETED'
}

export class Record {
    key: string;
    createdAt: Date;
    status: Status
}


  async saveRecord(record: Record): Promise<Record> {
    return this.put(record)
  };
  

Now, in my code , I have the something similar to:

 saveRecord(key: abc, status: Status.NEW)  
  ...
 saveRecord(key: abc, status: Status.UPDATED)

While in test, I am verifying using:

verify(mockRepository.saveRecord(objectContaining({abc, status: Status.NEW}))).once()     
verify(mockRepository.saveRecord(objectContaining({abc, status: Status.UPDATED}))).once()     

It doesn't work

while :
verify(mockRepository.saveRecord( objectContaining({abc, status: Status.UPDATED}))).times(2) //does work
I have debugged my current flow and I am sure, both the status updates are called ones

Sadly, mock is updated to capture arguments only for the last call, and all history before that is lost.

P.S: The record object in my implementation has some autogenerated fields, which is why I am using objectContaining()

@Markus-Ende
Copy link
Contributor

You can use capture as a work-around.

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

2 participants