Closed jorgemarcondes closed 1 year ago
hi @jorgemarcondes what kind of test are you trying to write?
@joaqcid Fantastic library, thanks for all you've done with it.
For unit tests, it would be nice to be able to do something like: store.dispatch(new MyStateUpdate('x')); // called from the component/service you're testing, of course. expect(store.selectSnapshot(MyState)).toEqual('x'); // check the store to make sure it's been updated as expected.
Doing this on a state object not backed by Firestore works, but I can't seem to get it to run when Firestore is involved. Maybe I'm just not mocking AngularFirestore correctly. Here's what I've tried so far:
export const angularFirestoreMock = {
doc: (...ignore: any) => ({
ref: {
withConverter: (...ignore: any) => ({}),
},
set: (_d: any) => new Promise
I've looked through the tests used in your package, but can't seem to get the formula right. Any ideas would be appreciated.
Hi @BL-marcusrogers
Assuming you have something like this in your @State
this.ngxsFirestoreConnect.connect(YOURACTION, {
to: ({ payload }) => this.YOUR_FIRESTORE_SERVICE.doc$(payload)
});
You should provide YOUR_FIRESTORE_SERVICE and mock doc$
or collection$
depending on what you need. Your mock could look something like this:
mockFIRESTORE_SERVICE = jest.fn(() => ({
collection$: new BehaviorSubject([{ raceId: 'a' }])
}));
let me know if this helps, if you want a complete example, take a look to this file
Have some example how to mock at unit tests?