soumak77 / firebase-mock

Firebase mock library for writing unit tests
https://soumak77.github.io/firebase-mock
350 stars 96 forks source link

When set is called with object with numeric keys, get returns an array #68

Closed nonplus closed 6 years ago

nonplus commented 6 years ago

Calling set with an object with numeric keys, causes .once('value') to return an array:

  const obj = { 1: "foo", 2: "bar" }
  await database.ref("expenses").set(obj);
  const snapshot = await database.ref("expenses").once("value");
  console.log("snapshot.val()", snapshot.val());

Output:

snapshot.val() [ undefined, 'foo', 'bar' ]

If the object has at least one non-numeric key, it is correctly returned.

soumak77 commented 6 years ago

This behavior was added with https://github.com/soumak77/firebase-mock/pull/37

@nonplus does firebase return the object or an array?

nonplus commented 6 years ago

OMG, that is the behavior that you also get from Firebase. 🤢

Well, that's pretty messed up, IMO, but firebase-mock behaves consistently.

Sorry about opening the issue.