cartant / firebase-nightlight

An in-memory, JavaScript mock for the Firebase Web API
https://cartant.github.io/firebase-nightlight/
Other
37 stars 8 forks source link

Is there a way to simulate failures? #16

Closed mjmaix closed 6 years ago

mjmaix commented 6 years ago

How should we simulate error for firebase database and authentication methods? I would like to know if anyone is doing something similar or workaround.

For example:

firebase.auth().signInWithEmailAndPassword(email, password)
    .catch(function(error) {
   //  I want to test this
});

adaNameRef.set({ first: 'Ada', last: 'Lovelace' })
  .then(function() {
    console.log('Synchronization succeeded');
  })
  .catch(function(error) {
   //  I want to test this
  });
cartant commented 6 years ago

Yes.

You can test signInWithEmailAndPassword failures by specifying identities when configuring the mock and by using invalid credentials when calling signInWithEmailAndPassword.

And you can force read and write failures by embedding errors - using the ".error" key - in the mock's database. This is mentioned in the README and there are numerous examples in the tests. The set test is here.

mjmaix commented 6 years ago

Thank you @Nicholas

On Fri, Nov 24, 2017 at 3:30 AM Nicholas Jamieson notifications@github.com wrote:

Closed #16 https://github.com/cartant/firebase-nightlight/issues/16.

— You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub https://github.com/cartant/firebase-nightlight/issues/16#event-1356264606, or mute the thread https://github.com/notifications/unsubscribe-auth/AB0J0yASmYZmtryabgXEvRYV8Uqz7jsCks5s5cfPgaJpZM4Qo2sS .