This function is used to change the behavior of an existing mock for a single invocation. Once invocation onAccess
has occurred, the mock will revert to whatever behavior it would have used had mockImplementationOnce()
not been called.
The following example creates a mock function using t.mock.property()
, calls the mock property, changes the mock implementation to a different value for the next invocation, and then resumes its previous behavior.
test('changes a mock behavior once', (t) => {
const obj = { foo: 1 };
const prop = t.mock.property(obj, 'foo', 5);
assert.strictEqual(obj.foo, 5);
prop.mock.mockImplementationOnce(25);
assert.strictEqual(obj.foo, 25);
assert.strictEqual(obj.foo, 5);
});