How to use the assert function from sinon
Find comprehensive JavaScript sinon.assert code examples handpicked from public code repositorys.
23 24 25 26 27 28 29 30 31 32
sandbox.restore(); }); it('should be called once', function () { myAPI.hello(); sinon.assert.calledOnce(myAPI.hello); }); it('should be called twice', function () { myAPI.hello();
810
1
3
+ 5 other calls in file
27 28 29 30 31 32 33 34 35
}); it('should be called twice', function () { myAPI.hello(); myAPI.hello(); sandbox.assert.calledTwice(myAPI.hello); }); }); ```
810
1
3
+ 3 other calls in file
563 564 565 566 567 568 569 570 571 572
await internalPromise(); sinon.assert.notCalled(cb); clock.tick(1); await internalPromise(); sinon.assert.calledOnce(cb); clock.tick(timeoutMs - artificialDelay); await internalPromise(); sinon.assert.calledOnce(cb);
208
537
83
+ 161 other calls in file
GitHub: mozilla/fxa
69 70 71 72 73 74 75 76 77 78
stubConstructor ); return pushbox .store(mockUid, mockDeviceIds[0], { test: 'data' }) .then(({ index }) => { sinon.assert.calledOnceWithExactly(stubDbModule.store, { uid: mockUid, deviceId: mockDeviceIds[0], data: 'eyJ0ZXN0IjoiZGF0YSJ9', ttl: 124457,
207
483
43
+ 54 other calls in file
92 93 94 95 96 97 98 99 100
// To User expect(message.toUser.id).to.equal(user2.id); expect(message.toUser.name).to.equal(user2.name); expect(message.toUser.email).to.equal(user2.email); // Should have dispatched notification to recipient sinon.assert.calledOnce(dispatchStub); }) ); });
29
346
9
+ 5 other calls in file
GitHub: julianpoy/RecipeSage
123 124 125 126 127 128 129 130 131 132
let subject = randomString(20); let html = randomString(20); let plain = randomString(20); return sendmail(toAddresses, ccAddresses, subject, html, plain).then(() => { sinon.assert.calledOnce(sesStub); sinon.assert.calledOnce(sesSendEmailStub); let { Destination: { CcAddresses,
29
346
9
+ 7 other calls in file
91 92 93 94 95 96 97 98 99 100
}, }; const checkFluxAvailabilityResult = await fluxNetworkHelper.checkFluxAvailability(req, mockResponse); sinon.assert.calledOnceWithExactly(stub, expectedAddress, axiosConfig); sinon.assert.calledWithExactly(stub, expectedAddressHome, axiosConfig); sinon.assert.calledOnceWithExactly(mockResponse.json, expectedMessage); expect(checkFluxAvailabilityResult).to.eql(expectedMessage); });
227
164
24
+ 74 other calls in file
GitHub: mozilla/fxa
815 816 817 818 819 820 821 822 823 824
sinon.assert.calledOnceWithExactly( directStripeRoutesInstance.customs.checkIpOnly, request, 'previewInvoice' ); sinon.assert.notCalled( directStripeRoutesInstance.stripeHelper.fetchCustomer ); sinon.assert.calledOnceWithExactly(
206
482
43
+ 72 other calls in file
GitHub: mozilla/fxa
347 348 349 350 351 352 353 354 355 356
email: 'joe@example.com', displayName: 'Joe Cool', idempotencyKey: uuidv4(), }); assert.deepEqual(actual, expected); sinon.assert.calledWithExactly( stripeHelper.stripeFirestore.insertCustomerRecord, uid, expected );
206
482
43
+ 196 other calls in file
73 74 75 76 77 78 79 80 81 82
assert.throws(() => supervisor.monitor('WA123', 'WA123', 123)); }); it('should make a valid POST request to API_V1', () => { supervisor.monitor('WA123', 'WA321'); sinon.assert.calledWith(request.post, 'Workspaces/baz/Tasks/WA123/Reservations/WA321', { Instruction: 'supervise', Supervisor: 'bar', SupervisorMode: 'monitor' }, API_V1 );
27
20
20
+ 5 other calls in file
71 72 73 74 75 76 77 78 79 80
req.body = { ...postBody } await controller(req, res, next) sinon.assert.calledWith(updateCompanyMock, res.locals.stripeAccount.stripeAccountId, { 'tax_id': '01234567' }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'company_number') sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripe.addPspAccountDetails}`)
13
19
18
+ 23 other calls in file
74 75 76 77 78 79 80 81 82 83
await controller(req, res, next) sinon.assert.calledWith(updateCompanyMock, res.locals.stripeAccount.stripeAccountId, { 'vat_id': 'GB999999973' }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'vat_number') sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripe.addPspAccountDetails}`) }) it('should not call Stripe when no vat number provided, should call connector, then redirect to add psp account details route', async function () {
13
19
18
+ 23 other calls in file
122 123 124 125 126 127 128 129 130 131
dob_day: dobDayNormalised, dob_month: dobMonthNormalised, dob_year: dobYearNormalised }) sinon.assert.calledWith(updateCompanyMock, res.locals.stripeAccount.stripeAccountId, { directors_provided: true }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'director') sinon.assert.calledWith(res.redirect, 303, `/account/${accountExternalId}${paths.account.stripe.addPspAccountDetails}`) sinon.assert.notCalled(req.flash) sinon.assert.notCalled(completeKycMock)
13
19
18
+ 42 other calls in file
130 131 132 133 134 135 136 137 138 139
'confirm-org-details': 'no' } controller(req, res, next) sinon.assert.calledWith(res.redirect, 303, '/account/a-valid-external-id/your-psp/a-valid-credential-id/update-organisation-details') }) it('when `yes` radio button is selected, then it should redirect to the `Stripe onboarding > add psp account details` redirect route', async () => { req.account.connectorGatewayAccountStripeProgress = { organisationDetails: false }
13
19
18
+ 18 other calls in file
55 56 57 58 59 60 61 62 63 64
setStripeAccountSetupFlagMock = sinon.spy(() => Promise.resolve()) const controller = getControllerWithMocks() await controller(req, res, next) sinon.assert.calledWith(updateBankAccountMock, res.locals.stripeAccount.stripeAccountId, { bank_account_sort_code: sanitisedSortCode, bank_account_number: sanitisedAccountNumber }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'bank_account')
13
19
18
+ 36 other calls in file
39 40 41 42 43 44 45 46 47 48
const getChannel = sandbox.spy(arnavmq.connection, 'getChannel'); const getChannelDefault = sandbox.stub(Channels.prototype, 'defaultChannel').resolves(channel); await arnavmq.consumer.consume(queueName, (message) => Promise.resolve(`${message}-test`)); sinon.assert.calledWith(getChannel, queueName, { prefetch: 5 }); sinon.assert.calledOnce(getChannelDefault); sinon.assert.calledWith(channel.assertQueue, queueName, { durable: true, persistent: true,
1
19
21
+ 15 other calls in file
375 376 377 378 379 380 381 382 383 384
} ] await controller(req, res, next) sinon.assert.calledWith(mockServiceService.updateService, serviceExternalId, expectedUpdateServiceRequest) sinon.assert.calledWith(res.redirect, 303, `/service/${serviceExternalId}/request-to-go-live/choose-how-to-process-payments`) }) it('should submit empty strings for optional fields left blank', async function () {
13
18
18
+ 71 other calls in file
118 119 120 121 122 123 124 125 126 127
const { openPr, stubs } = setup() await openPr(DEFAULT_ACTION_DATA) const branchName = `release/v${TEST_VERSION}` sinon.assert.calledWithExactly(stubs.execWithOutputStub, 'git', [ 'checkout', '-b', branchName, ])
7
15
62
+ 45 other calls in file
176 177 178 179 180 181 182 183 184 185 186 187
sinon.assert.calledOnceWithExactly( stubs.coreStub.setFailed, `Something went wrong while deleting the release. \n Errors: Something went wrong in the release` ) sinon.assert.notCalled(stubs.publishToNpmStub) } ) tap.test('Should publish to npm without optic', async () => {
7
15
62
+ 85 other calls in file
183 184 185 186 187 188 189 190 191 192
.calledWith('wrong-id') .should.equal(false) }) it('should only add the existing project to the zip', function () { sinon.assert.calledOnce(this.archive.append) this.archive.append .calledWith(this.zip_streams['project-1'], { name: this.project_names['project-1'] + '.zip', })
0
2
1
+ 2 other calls in file
sinon.stub is the most popular function in sinon (5777 examples)