Skip to content

Instantly share code, notes, and snippets.

@mchirico
Created July 9, 2020 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchirico/bb5ea5b11860ab37abc0f44457b5843a to your computer and use it in GitHub Desktop.
Save mchirico/bb5ea5b11860ab37abc0f44457b5843a to your computer and use it in GitHub Desktop.
Needs to be cleaned up... sinon fake..
import "mocha";
import { expect } from "chai";
import { set, db } from "../src/firebasekick";
import * as sinon from "sinon";
import * as firebase from "@firebase/testing";
import admin from "firebase-admin";
import DocumentReference = admin.firestore.DocumentReference;
import DocumentData = admin.firestore.DocumentData;
// stub(obj, 'meth').callsFake(fn)
const MY_PROJECT_ID = "septapig";
function getDBadmin(): firebase.firestore.Firestore {
return firebase
.initializeAdminApp({
projectId: MY_PROJECT_ID,
})
.firestore();
}
function s(path: string): DocumentReference<DocumentData> | any {
const mdb = getDBadmin();
console.log("path:", path);
// return mdb.doc("zz/b");
return mdb.doc(path);
}
describe.skip("mock ...", function () {
beforeEach(async function () {
sinon.stub(db, "doc").callsFake(s);
});
afterEach(function () {
// Cancel snapshot listener
});
it("Test snapshot listener", async function () {
//const path = "test/express/task/0";
const path = "test/0";
const data = { a: "one", time: new Date(), minutes: 35 };
await set(path, data);
const testQuery = db.doc(path);
await firebase.assertSucceeds(testQuery.get());
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment