Giter Club home page Giter Club logo

firebase-dbfake's Introduction

firebase-dbfake is a fake library to assist you in unit testing your JavaScript projects that store data in Firebase.

Quick Overview

When you store data in firebase, you have two basic objects that you interact with:

  • reference describes the location in your document store you would like to work with
  • dataSnapshot a representation of the data at a reference

Don't Mock What You Do Not Own

The book Growing Object Oriented Software, Guided by Tests states that you should never mock interfaces that you don't own. firebase-dbfakes is designed to make it simple for you to obey this principle. When you call once() on a reference, you get back a promise and if all goes well that resolves to a DataSnapshot. The core principle that started firebase-dbfake is that you don't own once() and you should have a shim that calls it. The shim returns you a promise which resolves to a DataSnapshot. Once you have that in place, you can inject a firebase-dbfake.snapshot and unit test to your hearts content.

firebase-dbfake

firebase-dbfake exposes four methods to help you in your unit testing:

  • reference returns you an object with the same api as a real Firebase reference, but it doesn't do much of anything. It does enable you to supply your own behavior needed for your tests.
  • snapshot returns you an object with the same api as a real Firebase dataSnapshot, but it won't connect to Firebase.
  • resolveSnapshot returns a promise that resolves a snapshot. You should use this when you mock your code that would interact with Firebase.
  • memoizeSnapshot a short hand for writing a function that returns a promise which resolves a snapshot. Again, used when mocking your data layer.

firebase-dbfake's People

Contributors

exploremqt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.