Last active
November 4, 2019 19:35
-
-
Save sbatson5/fd79678182169a197195ec2ab009901a to your computer and use it in GitHub Desktop.
Testing firestore queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// These are the mocked version of some firestore methods | |
// And we want to assert they are called correctly | |
const { | |
mockCollection, | |
mockGet, | |
mockWhere, | |
} = require('firestore-jest-mock/mocks/firestore'); | |
const { mockFirebase } = require('firestore-jest-mock'); | |
describe('Querying events', () => { | |
mockFirebase({ | |
database: { | |
events: [{ id: 'abc123', state: 'vermont' }, { id: '123abc', state: 'maine' }] | |
} | |
}); | |
test('It can query by state', async () => { | |
// From https://gist.github.com/sbatson5/c9d018a3d46de1ce6be770848f88e47f | |
maybeGetEventsByState('vermont'); | |
// Assert we are looking at the right collection | |
expect(mockCollection).toHaveBeenCalledWith('events'); | |
// Assert that the correct state was queried | |
expect(mockWhere).toHaveBeenCalledWith('state', '==', 'vermont'); | |
// Assert that we finally request the data | |
expect(mockGet).toHaveBeenCalled(); | |
}); | |
test('It can request all', async () => { | |
// From https://gist.github.com/sbatson5/c9d018a3d46de1ce6be770848f88e47f | |
maybeGetEventsByState(); | |
// Assert we are looking at the right collection | |
expect(mockCollection).toHaveBeenCalledWith('events'); | |
// Assert that we make no queries | |
expect(mockWhere).not.toHaveBeenCalled(); | |
// Assert that we finally request the data | |
expect(mockGet).toHaveBeenCalled(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment