Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('startAt - should re-run a query when the observable value has emitted', (done: any) => {
const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
query: {
orderByKey: true,
startAt: subject
}
});
queryTest(observable, subject, done);
});
it('should have a a FirebaseListObservable shape when queried', () => {
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: '1'
}
});
expect(observable.push instanceof Function).toBe(true);
expect(observable.update instanceof Function).toBe(true);
expect(observable.remove instanceof Function).toBe(true);
});
});
it('should throw an error if startAt and endAt is used with equalTo', () => {
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: 10,
endAt: 100,
startAt: 103
}
});
expect(observable.subscribe).toThrowError();
});
it('should call off on all events when disposed', (done: any) => {
const questionRef = app.database().ref().child('questions');
subscription = FirebaseListFactory(questionRef).subscribe(_ => {
let firebaseSpy = spyOn(questionRef, 'off').and.callThrough();
expect(firebaseSpy).not.toHaveBeenCalled();
subscription.unsubscribe();
expect(firebaseSpy).toHaveBeenCalled();
done();
});
});
it('should accept a Firebase db ref in the constructor', () => {
const list = FirebaseListFactory(app.database().ref(`questions`));
expect(list instanceof FirebaseListObservable).toBe(true);
});
.then(() => {
let query1 = FirebaseListFactory(app.database().ref(`questions`), {
query: {
orderByChild: 'data',
startAt: { value: 0 }
}
});
let promise1 = toPromise.call(take.call(query1, 1));
let query2 = FirebaseListFactory(app.database().ref(`questions`), {
query: {
orderByChild: 'data',
startAt: { value: 0, key: 'val2' }
}
});
let promise2 = toPromise.call(take.call(query2, 1));
Promise.all([promise1, promise2]).then(([list1, list2]) => {
expect(list1.map((i: any) => i.$key)).toEqual(['val1', 'val2', 'val3']);
expect(list2.map((i: any) => i.$key)).toEqual(['val2', 'val3']);
done();
});
})
.catch(done.fail);
beforeEach((done: any) => {
toKey = (val: any) => val.key;
val1 = { key: 'key1' };
val2 = { key: 'key2' };
val3 = { key: 'key3' };
app.database().ref().remove(done);
questions = FirebaseListFactory(app.database().ref(`questions`));
questionsSnapshotted = FirebaseListFactory(app.database().ref(`questionssnapshot`), { preserveSnapshot: true });
ref = questions.$ref;
refSnapshotted = questionsSnapshotted.$ref;
});
beforeEach((done: any) => {
toKey = (val: any) => val.key;
val1 = { key: 'key1' };
val2 = { key: 'key2' };
val3 = { key: 'key3' };
app.database().ref().remove(done);
questions = FirebaseListFactory(app.database().ref(`questions`));
questionsSnapshotted = FirebaseListFactory(app.database().ref(`questionssnapshot`), { preserveSnapshot: true });
ref = questions.$ref;
refSnapshotted = questionsSnapshotted.$ref;
});
.then(() => {
let subject = new Subject();
let query = FirebaseListFactory(app.database().ref(`questions`), {
query: {
orderByChild: 'even',
equalTo: subject
}
});
query = map.call(query, (list: any, index: any) => {
switch (index) {
case 0:
subject.next(true);
break;
case 1:
questions.$ref.ref.update({
key3: { even: false, value: 3 },
key4: { even: true, value: 4 }
});
.then(() => {
let query1 = FirebaseListFactory(app.database().ref(`questions`), {
query: {
orderByChild: 'data',
equalTo: { value: 0 }
}
});
let promise1 = toPromise.call(take.call(query1, 1));
let query2 = FirebaseListFactory(app.database().ref(`questions`), {
query: {
orderByChild: 'data',
equalTo: { value: 0, key: 'val2' }
}
});
let promise2 = toPromise.call(take.call(query2, 1));
Promise.all([promise1, promise2]).then(([list1, list2]) => {