Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example of Sinon Fake #37

Open
mchirico opened this issue Jul 9, 2020 · 1 comment
Open

Example of Sinon Fake #37

mchirico opened this issue Jul 9, 2020 · 1 comment

Comments

@mchirico
Copy link
Owner

mchirico commented Jul 9, 2020

working

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());
  });
});

@tacomonkautobot
Copy link

mchirico,
Thanks for opening this issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant