mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-28 20:25:41 +08:00
[tests][firestore] add document SnapshotError tests
This commit is contained in:
@@ -4,10 +4,14 @@ const {
|
||||
COL2_DOC_1_ID,
|
||||
cleanCollection,
|
||||
COL2_DOC_1_PATH,
|
||||
TEST_COLLECTION_NAME_DYNAMIC,
|
||||
resetTestCollectionDoc,
|
||||
TEST_COLLECTION_NAME_DYNAMIC,
|
||||
} = TestHelpers.firestore;
|
||||
|
||||
function getSnapshotErrorClass() {
|
||||
return jet.require('src/modules/firestore/SnapshotError');
|
||||
}
|
||||
|
||||
describe('firestore()', () => {
|
||||
describe('DocumentReference', () => {
|
||||
before(async () => {
|
||||
@@ -133,6 +137,34 @@ describe('firestore()', () => {
|
||||
await sleep(50);
|
||||
});
|
||||
|
||||
it('snapshot error returns instance of SnapshotError', () => {
|
||||
let unsubscribe;
|
||||
const { reject, resolve, promise } = Promise.defer();
|
||||
const collection = firebase.firestore().doc('blocked-collection/nope');
|
||||
|
||||
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/nope');
|
||||
snapshotError.code.should.equal('firestore/permission-denied');
|
||||
resolve();
|
||||
},
|
||||
};
|
||||
|
||||
unsubscribe = collection.onSnapshot(observer);
|
||||
return promise;
|
||||
});
|
||||
|
||||
it('calls callback with the initial data and then when value changes', async () => {
|
||||
await resetTestCollectionDoc(COL2_DOC_1_PATH, { name: 'doc1' });
|
||||
const docRef = test2DocRef(COL2_DOC_1_ID);
|
||||
|
||||
Reference in New Issue
Block a user