gustavohenke / mockbase Goto Github PK
View Code? Open in Web Editor NEWFirebase v7+ mock.
Home Page: https://www.npmjs.com/package/mockbase
Firebase v7+ mock.
Home Page: https://www.npmjs.com/package/mockbase
Line 181 in bcb6bdb
It would be great if a Mock Sign In could be used more then once. In testing frameworks like jest
there are methods that allow mocking only once and mocking more then once and having similar functionality with this library.
Code in question:
mockbase/firestore/document-reference.ts
Lines 142 to 174 in f5b0184
Example on how it is used from firebase in AngularFire
return new Observable(subscriber => {
let unsubscribe;
if (scheduler != null) {
scheduler.schedule(() => {
unsubscribe = ref.onSnapshot(subscriber);
});
} else {
unsubscribe = ref.onSnapshot(subscriber);
}
return () => {
if (unsubscribe != null) {
unsubscribe();
}
};
});
By destructuring the subscriber it results in this error.
Unhandled Promise rejection: Cannot read property 'isStopped' of undefined ; Zone: ProxyZone ; Task: Promise.then ; Value: TypeError: Cannot read property 'isStopped' of undefined
Because next()
references this
internally in the RxJS subscriber it needs to be called with dot notation of the subscriber.
First I would like to thank you Gustavo for all the hard work you have put into mocking Firebase.
I have been attempting to build out proper unit test when using Angular Fire and your mock of Firebase has been instrumental in building out proper mocks.
I am running into an issue with your mock of Firestore though. That is that it is only sending me the added
docs but not removed
or modified
.
This is the section of code that I am getting stuck and and not getting past the short circuit.
mockbase/firestore/query-snapshot.ts
Lines 29 to 37 in e271ba2
This is where the lastSnapshot
seems like it should be set to prevent that short circuit
Lines 41 to 55 in e271ba2
Code I am using
const subject = new Subject();
this.app
.firestore()
.collection(path)
.onSnapshot({
next: (collection) => {
subject.next(
collection.docChanges().map(({ type, doc }) => ({ type, payload: { doc } }))
);
},
error: (err) => subject.error(err),
complete: () => subject.complete(),
});
subject.subscribe(console.log);
I have played around with it for a bit but can't seem to figure out the exact cause. My guess is either (a) lastSnapshot
isn't being set OR (b) the current snapshot and lastSnapshot are always in sync, or at least at the time when docChanges()
runs from within a onSnapshot()
Again thank you so much for your work. Let me know if you need any more information or have any work arounds.
auth/email-already-in-use
Thrown if there already exists an account with the given email address.
https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword
Lines 112 to 117 in aa58af5
In some libraries it is assumed that UserCredential
will include additionalUserInfo
. While the typing of UserCredential
is clear that additionalUserInfo
can be null or undefined many libraries assume that if the sign in came from a supported platform (like Google) then the additionalUserInfo
will be included.
Additionally libraries, including this one, may have branching behavior based on what is included in additionalUserInfo
so being able to express this when setting up the mock would allow for testing that additional behavior.
Implement features around user linking:
In this section
Lines 67 to 78 in 61b9467
When used with
public readonly authState = new Observable<User | null>(
this.auth.onAuthStateChanged.bind(this.auth)
);
throws the following error.
TypeError: nextOrObserver is not a function
It should be noted that nextOrObserver
is a SwitchMapSubscriber
when this error occurs.
Simply checking typeof
should allow us to determine if nextOrObserver
is next
or observer
observer
seem to be expecting you to call nest()
on them with the user.
Here is the firebase implementation of this function for additional reference
https://github.com/firebase/firebase-js-sdk/blob/35bc0a2eea98d9796023f15cd5783700d45ccc4d/packages/auth/src/auth.js#L1442-L1472
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.