Skip to content

Commit

Permalink
Add mockQueryOnSnapshotUnsubscribe as unsubscribe mock function retur…
Browse files Browse the repository at this point in the history
…ned by onSnapshot (#189)
  • Loading branch information
Pascal Viney committed Apr 12, 2024
1 parent 4c3d4b8 commit 317d3d0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion __tests__/full-setup-library-firestore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe.each([
mockBatchCreate,
mockSettings,
mockOnSnapShot,
mockQueryOnSnapshotUnsubscribe,
mockListCollections,
mockTimestampNow,
mockCreate,
Expand Down Expand Up @@ -378,7 +379,7 @@ describe.each([

await flushPromises();

expect(unsubscribe).toBeInstanceOf(Function);
expect(unsubscribe).toBe(mockQueryOnSnapshotUnsubscribe);
expect(mockWhere).toHaveBeenCalled();
expect(mockOnSnapShot).toHaveBeenCalled();
});
Expand Down
3 changes: 2 additions & 1 deletion __tests__/full-setup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe.each`
mockWithConverter,
FakeFirestore,
mockQueryOnSnapshot,
mockQueryOnSnapshotUnsubscribe,
mockTimestampNow,
mockRecursiveDelete,
} = require('firestore-jest-mock/mocks/firestore');
Expand Down Expand Up @@ -411,7 +412,7 @@ describe.each`

await flushPromises();

expect(unsubscribe).toBeInstanceOf(Function);
expect(unsubscribe).toBe(mockQueryOnSnapshotUnsubscribe);
expect(mockWhere).toHaveBeenCalled();
expect(mockOnSnapShot).not.toHaveBeenCalled();
expect(mockQueryOnSnapshot).toHaveBeenCalled();
Expand Down
1 change: 1 addition & 0 deletions src/mocks/firestore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export const mockOffset: jest.Mock;
export const mockStartAfter: jest.Mock;
export const mockStartAt: jest.Mock;
export const mockQueryOnSnapshot: jest.Mock;
export const mockQueryOnSnapshotUnsubscribe: jest.Mock;
export const mockWithConverter: jest.Mock;

// Mocks exported from Timestamp
Expand Down
1 change: 1 addition & 0 deletions src/mocks/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export const mocks: {
mockStartAfter: jest.Mock,
mockStartAt: jest.Mock,
mockQueryOnSnapshot: jest.Mock,
mockQueryOnSnapshotUnsubscribe: jest.Mock,
mockWithConverter: jest.Mock,
};
6 changes: 4 additions & 2 deletions src/mocks/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const mockOffset = jest.fn();
const mockStartAfter = jest.fn();
const mockStartAt = jest.fn();
const mockQueryOnSnapshot = jest.fn();
const mockQueryOnSnapshotUnsubscribe = jest.fn();
const mockWithConverter = jest.fn();

class Query {
Expand Down Expand Up @@ -140,8 +141,8 @@ class Query {
}
}

// Returns an unsubscribe function
return () => {};
// Returns an unsubscribe mock
return mockQueryOnSnapshotUnsubscribe;
}
}

Expand All @@ -157,6 +158,7 @@ module.exports = {
mockStartAfter,
mockStartAt,
mockQueryOnSnapshot,
mockQueryOnSnapshotUnsubscribe,
mockWithConverter,
},
};

0 comments on commit 317d3d0

Please sign in to comment.