Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock the unsubscribe callback returned by onSnapshot #190

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
};
Loading