You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More concretely, I'm trying to stub the ConnectionPool method of the library as follows (with mocha and chai):
mockDB.test.ts
import * as sinon from 'sinon';
import * as mssql from 'mssql';
describe('EmployeeDiscountController', function () {
beforeEach(async function() {
sinon.stub(mssql, 'ConnectionPool').returns({
ConnectionPool: sinon.stub().returns({
request: () => {},
connect: () => {}
})
});
});
});
(I skipped all the unnecessary parts in the code.)
Unfortunately, I get the following error:
TypeError: Descriptor for property ConnectionPool is non-configurable and non-writable
at assertValidPropertyDescriptor (node_modules\sinon\lib\sinon\stub.js:138:15)
at Function.stub (node_modules\sinon\lib\sinon\stub.js:89:5)
at Object.stub (node_modules\sinon\lib\sinon\sandbox.js:389:39)
Do you know why this is?
I saw a PR that would resolve this issue but as I am using the latest sinon version (15.2.0) this problem seems to persist for me.
Is it advisable to even use sinon to mock such packages? I don't very little experience in writing tests and am actually using sinon the first time.
Thank you very much for your help!
The text was updated successfully, but these errors were encountered:
Hi, this is is more less exactly what I covered in this new article I just wrote on different approaches to testing. You can see if you find your answer there: #2540
My article covers different approaches on how you can attach this (I cover 3 very different approaches, from tool configuration, external loaders and through exposing your code).
Describe the bug
I'm trying to mock a database connection for which I'm using the tedious node-mssql library (https://github.com/tediousjs/node-mssql)
More concretely, I'm trying to stub the ConnectionPool method of the library as follows (with mocha and chai):
mockDB.test.ts
(I skipped all the unnecessary parts in the code.)
Unfortunately, I get the following error:
Do you know why this is?
I saw a PR that would resolve this issue but as I am using the latest sinon version (15.2.0) this problem seems to persist for me.
Is it advisable to even use sinon to mock such packages? I don't very little experience in writing tests and am actually using sinon the first time.
Thank you very much for your help!
The text was updated successfully, but these errors were encountered: