forest-fire / firemock

Firebase 3.0 mocking and mock generation all with Typescript typings
https://www.firemock.com/
MIT License
6 stars 5 forks source link

[BUGFIX] Datasnapshot exists check by undefined #2

Open jampueroc opened 6 years ago

jampueroc commented 6 years ago

Hi, I found that datasnapshot can be undefined and in your code only checks for nulls, so i added this check.

Here is an example of this bug

describe('Bug', ()=>{
  let databaseMock;
  before(() => {
    const Mock = require('firemock').Mock;
    databaseMock = new Mock(
      {
        place:{
          'id1':{
            id: "-hello"
          },
          'id2':{
            id: "-bye"
          },
        }
      });
  });

  after(() => {
  });

  it('should be fail', ()=>{
    const path = 'place/id3';
    return databaseMock.ref(path).set({id:'bug'}).then(()=>{
      return databaseMock.ref(path).remove().then(()=>{
        const elementDeleted = databaseMock.ref(path).onceSync("value");
        assert.isUndefined(elementDeleted.val()); // this works
        assert.isFalse(elementDeleted.exists()); // this fail
      })
    });
  })
});

thanks!

yankeeinlondon commented 4 years ago

So sorry, just saw this PR now ... two years later :)