const test = require("firebase-functions-test")({
projectId: "project-id",
});
describe('test', () => {
afterEach(async () => {
await test.firestore.clearFirestoreData({ projectId: "project-id" });
});
it('test1', () => {
// test that involes database changes
});
it('test2', () => {
// test that involes database changes
});
});
in order to implement tests I think I would need change:
"test": "mocha .tmp/spec/index.spec.js"
to
"test": "firebase emulators:exec 'mocha .tmp/spec/index.spec.js'"
I want to know if there is a better way to implement tests before I started.
Description
Added a function to clear all firestore data between tests. Similar to https://github.com/firebase/firebase-js-sdk/blob/master/packages/testing/src/api/index.ts#L233
This makes it easier to run tests in offline mode
Code sample
in order to implement tests I think I would need change:
"test": "mocha .tmp/spec/index.spec.js"
to"test": "firebase emulators:exec 'mocha .tmp/spec/index.spec.js'"
I want to know if there is a better way to implement tests before I started.