testing-patterns-nodejs
Installation
SKILL.md
Testing Couchbase Node.js Applications
Unit Testing
Mock the collection object using Jest. Install: npm install --save-dev jest.
test('getUser returns correct document', async () => {
const mockGet = jest.fn().mockResolvedValue({
content: { name: 'Alice', email: 'alice@example.com' }
});
const mockCollection = { get: mockGet };
const repo = new UserRepository(mockCollection);
const user = await repo.getUser('user::alice');