[tests][firestore] add collection SnapshotError tests

This commit is contained in:
Salakar
2018-09-21 00:12:46 +01:00
parent 7041403c4d
commit f9e9179242

View File

@@ -7,6 +7,10 @@ const {
TEST_COLLECTION_NAME_DYNAMIC,
} = TestHelpers.firestore;
function getSnapshotErrorClass() {
return jet.require('src/modules/firestore/SnapshotError');
}
describe('firestore()', () => {
describe('CollectionReference', () => {
describe('onSnapshot()', () => {
@@ -431,6 +435,36 @@ describe('firestore()', () => {
unsubscribe();
});
it('snapshot error returns instance of SnapshotError', () => {
let unsubscribe;
const { reject, resolve, promise } = Promise.defer();
const collection = firebase
.firestore()
.collection('blocked-collection');
const observer = {
next: () => {
unsubscribe();
reject(new Error('Did not error!'));
},
error: snapshotError => {
snapshotError.should.be.instanceOf(getSnapshotErrorClass());
snapshotError.code.should.be.a.String();
snapshotError.path.should.be.a.String();
snapshotError.appName.should.be.a.String();
snapshotError.message.should.be.a.String();
snapshotError.nativeErrorMessage.should.be.a.String();
snapshotError.appName.should.equal('[DEFAULT]');
snapshotError.path.should.equal('blocked-collection');
snapshotError.code.should.equal('firestore/permission-denied');
resolve();
},
};
unsubscribe = collection.onSnapshot(observer);
return promise;
});
it('errors when invalid parameters supplied', async () => {
const colRef = firebase
.firestore()