First, I've gone through all of the other posts related to this topic and implemented Sinon.sandbox()
. Unfortunately, I am still getting the following error:
TypeError: Attempted to wrap createMessage which is already wrapped
Note that I'm using Ava for testing and in this case, I've set it to run in serial mode rather than parallel.
// Load modules
import Queue from '../lib/queue';
import test from 'ava';
import Sinon from 'sinon';
import Proxyquire from 'proxyquire';
// Globals
const FAKE_APPOINTMENT_ID = 'ab9e9495-fdbf-4607-8f57-01c6e91bd8f5';
let push;
let queueStub;
let sandbox;
// Test setup
test.beforeEach(() => {
// create the sinon sandbox
sandbox = Sinon.sandbox.create();
// stub the queue module
queueStub = sandbox.stub(Queue.prototype);
// inject the stub
push = Proxyquire('../lib/push', {
'./queue': queueStub
});
});
test.afterEach(t => {
sandbox.restore();
});
// Tests
test.only('sends an appointment approved push notification', async t => {
await push.appointmentApproved(FAKE_APPOINTMENT_ID);
t.true(queueStub.createMessage.calledOnce);
});
test.only('sends an appointment cancelled push notification', async t => {
await push.appointmentCancelled(FAKE_APPOINTMENT_ID);
t.true(queueStub.createMessage.calledOnce);
});
test.only('sends an appointment updated push notification', async t => {
await push.appointmentUpdated(FAKE_APPOINTMENT_ID);
t.true(queueStub.createMessage.calledOnce);
});
I've also tried switching beforeEach
to before
, and while the first of the 3 tests passes, the last two complete because the stub's call count never seems to reset. Maybe I'm misunderstanding the purpose of restore()
Thanks!