l2beat / earl

☕ Ergonomic, modern and type-safe assertion library for TypeScript
https://earl.fun/
MIT License
256 stars 19 forks source link

Feature request: reset function for MockObjects #292

Closed dhardtke closed 2 months ago

dhardtke commented 11 months ago

If I have a MockObject and I want to reset that right now I have to reset each individual MockFn separately.

Instead, it would be handy if I could just call a reset function and pass the MockObject, e.g.

const mockObj = mockObject<UserService>({
    authenticate(id: string): Token {
        // ...
    }
});
resetMockObject(mockObj);

Notice: I think it is better to provide an exported function that takes a MockObject than to provide a reset() function on every instance of MockObject to avoid naming collisions. Alternatively, the name could be very unique (think "resetMockObject()" on the MockObject) but this is kind of a workaround, only.