Skip to content

Commit 4637ca2

Browse files
committed
test: Upgrade to Sinon v2
1 parent ab28dfa commit 4637ca2

File tree

3 files changed

+14
-29
lines changed

3 files changed

+14
-29
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"semver": "^5.1.0",
3737
"should": "^11.1.0",
3838
"should-sinon": "0.0.5",
39-
"sinon": "^1.17.3"
39+
"sinon": "^2.0.0"
4040
},
4141
"scripts": {
4242
"test": "grunt"

test/unit/Connection.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('Connection', () => {
1515
const expectedValues = ['solution'];
1616
function expectedCb() { /* no-op */ }
1717

18-
sinon.stub(connection, 'query', function(sql, values, cb) {
18+
sinon.stub(connection, 'query').callsFake((sql, values, cb) => {
1919
sql.should.equal(expectedSql);
2020
values.should.equal(expectedValues);
2121
cb.should.equal(expectedCb);

test/unit/PoolPlus.test.js

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,9 @@ describe('PoolPlus', () => {
144144
const error = new Error('test error');
145145

146146
before(() => {
147-
sinon.stub(pool, 'getConnection', function(cb) {
148-
process.nextTick(() => cb(error));
149-
});
150-
sinon.stub(TableDefinition.prototype, 'genSyncOperations', function(cb) {
151-
process.nextTick(() => cb(null, [{sql: 'pretend sql', type: -1}]));
152-
});
147+
sinon.stub(pool, 'getConnection').yieldsAsync(error);
148+
sinon.stub(TableDefinition.prototype, 'genSyncOperations')
149+
.yieldsAsync(null, [{sql: 'pretend sql', type: -1}]);
153150
});
154151

155152
after(() => {
@@ -172,9 +169,7 @@ describe('PoolPlus', () => {
172169
const error = new Error('test error');
173170

174171
before(() => {
175-
sinon.stub(TableDefinition.prototype, 'genSyncOperations', function(cb) {
176-
process.nextTick(() => cb(error));
177-
});
172+
sinon.stub(TableDefinition.prototype, 'genSyncOperations').yieldsAsync(error);
178173
});
179174

180175
after(() => {
@@ -196,13 +191,9 @@ describe('PoolPlus', () => {
196191
const error = new Error('test error');
197192

198193
before(() => {
199-
sinon.stub(Connection.prototype, 'query', function() {
200-
const cb = arguments.length > 0 && arguments[arguments.length - 1];
201-
process.nextTick(() => cb(error));
202-
});
203-
sinon.stub(TableDefinition.prototype, 'genSyncOperations', function(cb) {
204-
process.nextTick(() => cb(null, [{sql: 'pretend sql', type: -1}, {sql: '', type: 0}]));
205-
});
194+
sinon.stub(Connection.prototype, 'query').yieldsAsync(error);
195+
sinon.stub(TableDefinition.prototype, 'genSyncOperations')
196+
.yieldsAsync(null, [{sql: 'pretend sql', type: -1}, {sql: '', type: 0}]);
206197
});
207198

208199
after(() => {
@@ -229,7 +220,7 @@ describe('PoolPlus', () => {
229220
const expectedValues = ['solution'];
230221
function expectedCb() { /* no-op */ }
231222

232-
sinon.stub(pool, 'query', function(sql, values, cb) {
223+
sinon.stub(pool, 'query').callsFake((sql, values, cb) => {
233224
sql.should.equal(expectedSql);
234225
values.should.equal(expectedValues);
235226
cb.should.equal(expectedCb);
@@ -425,9 +416,7 @@ describe('PoolPlus', () => {
425416
const error = new Error('test error');
426417

427418
before(() => {
428-
sinon.stub(pool, 'getConnection', function(cb) {
429-
process.nextTick(() => cb(error));
430-
});
419+
sinon.stub(pool, 'getConnection').yieldsAsync(error);
431420
});
432421

433422
after(() => {
@@ -454,9 +443,7 @@ describe('PoolPlus', () => {
454443
const error = new Error('test error');
455444

456445
before(() => {
457-
sinon.stub(Connection.prototype, 'beginTransaction', function(cb) {
458-
process.nextTick(() => cb(error));
459-
});
446+
sinon.stub(Connection.prototype, 'beginTransaction').yieldsAsync(error);
460447
});
461448

462449
after(() => {
@@ -483,9 +470,7 @@ describe('PoolPlus', () => {
483470
const error = new Error('test error');
484471

485472
before(() => {
486-
sinon.stub(Connection.prototype, 'commit', function(cb) {
487-
process.nextTick(() => cb(error));
488-
});
473+
sinon.stub(Connection.prototype, 'commit').yieldsAsync(error);
489474
});
490475

491476
after(() => {
@@ -534,7 +519,7 @@ describe('PoolPlus', () => {
534519
sinon.stub(require.cache[require.resolve('../../lib/TableDefinition')], 'exports');
535520

536521
// Prevent checking for duplicate table definitions
537-
sinon.stub(Map.prototype, 'has', () => false);
522+
sinon.stub(Map.prototype, 'has').returns(false);
538523

539524
MockPool = require('../../lib/PoolPlus');
540525
TableDefinitionStub = require('../../lib/TableDefinition');

0 commit comments

Comments
 (0)