You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow to reset the value of MockFunctionContext.#calls #45795
I use globally mocked objects in my tests to allow them to run without an environment:
// Something that looks like a nodemailer objectexportconstmailer={sendMail: mock.fn(()=>Promise.resolve())};
Because it's global, tests can pollute each other:
it('works',()=>{mailer.sendMail({to: "user@example.com"});assert.equal(mailer.sendMail.mock.callCount(),1);});it('also works',()=>{mailer.sendMail({to: "user@example.com"});assert.equal(mailer.sendMail.mock.callCount(),1);// It fails here, `callCount()` is now 2});
What is the feature you are proposing to solve the problem?
I want to be able to reset mailer.sendMail.mock.calls:
describe('something',()=>{beforeEach(()=>{mailer.sendMail.mock.reset();// Method name open to bikeshedding})})
Activity
GauBen commentedon Dec 9, 2022
Addressed by #45710