'How to mock a Firebase set() with Sinon?
I am trying to test this Firebase access code
let writeHomePromise = admin
.database()
.ref(
"sm_matches/" +
match.date +
"/" +
match.homeTeam.name +
"/homeNGSPlayers"
)
.set(match.homePlayers);
using Sinon.
I create a match with
const match = {
'date' : '2902199',
'homeTeam' : '{"name" : "My_team"}',
'homePlayers' : ["Nomran Mailer", "Peter Bonetti"],
'awayPlayers': ["Ernst Blofeld", "Postman Pat"],
};
And I am trying, unsuccessfully, to mock that code with
let refStub = sinon.stub();
let setStub = sinon.stub();
refStub.withArgs('sm_matches/2902199/My_team/homeNGSPlayers').returns(
{push: () => ({key: 'fakeKey', set: setStub})}
);
which gives me TypeError: Cannot read property 'set' of undefined.
This is my first foray into Sinon, and even something this simple is giving me problems.
What am I doing wrongly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
