firebase-nightlight
is an in-memory, JavaScript mock for the Firebase Web API.
Example
import * as firebase from "firebase/app";
import { expect } from "chai";
import { Mock } from "firebase-nightlight";
describe("something", () => {
let mockDatabase: any;
let mockApp: firebase.app.App;
beforeEach(() => {
mockDatabase = {
content: {
lorem: "ipsum"
}
};
const mock = new Mock({
database: mockDatabase,
identities: [{
email: "alice@firebase.com",
password: "wonderland"
}]
});
mockApp = mock.initializeApp({});
});
it("should do something with the mock", () => {
return mockApp
.auth()
.signInWithEmailAndPassword("alice@firebase.com", "wonderland")
.then((user) => {
expect(user).to.exist;
expect(user).to.have.property("email", "alice@firebase.com");
expect(user).to.have.property("uid");
return mockApp
.database()
.ref()
.once("value");
})
.then((snapshot) => {
expect(snapshot.val()).to.deep.equal({ lorem: "ipsum" });
return mockApp
.database()
.ref()
.update({ lorem: "something else" });
})
.then(() => {
expect(mockDatabase.content).to.deep.equal({ lorem: "something else" });
return mockApp
.auth()
.signOut();
});
});
});