Originally published at recca0120.github.io The most common testing pattern I see looks like this: test('saves user data', () => { const mockStorage = { set: vi.fn(), get: vi.fn().mockReturnValue(null), }; const service = new UserService(mockStorage); service.save({ id: 1, name: 'Alice' }); expect(mockStorage.set).toHaveBeenCalledWith('user:1', { id: 1, name: 'Alice' }); }); Looks fine. Tests
DI + Fake + in-memory: Writing Frontend Tests That Survive Refactors
Recca Tsai·Dev.to··1 min read
D
Continue reading on Dev.to
This article was sourced from Dev.to's RSS feed. Visit the original for the complete story.