Skip to content

Commit aec4b5c

Browse files
test: rely on chai type assertions instead of type casting
1 parent a1c6c1a commit aec4b5c

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

test/integration/bulk-load-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('BulkLoad', function() {
129129
it('fails if the column definition does not match the target table format', function(done) {
130130
const bulkLoad = connection.newBulkLoad('#tmpTestTable2', (err, rowCount) => {
131131
assert.instanceOf(err, RequestError, 'An error should have been thrown to indicate the incorrect table format.');
132-
assert.strictEqual(/** @type {RequestError} */(err).message, 'An unknown error has occurred. This is likely because the schema of the BulkLoad does not match the schema of the table you are attempting to insert into.');
132+
assert.strictEqual(err.message, 'An unknown error has occurred. This is likely because the schema of the BulkLoad does not match the schema of the table you are attempting to insert into.');
133133

134134
assert.isUndefined(rowCount);
135135

@@ -376,7 +376,7 @@ describe('BulkLoad', function() {
376376
].join(' ');
377377

378378
assert.instanceOf(err, RequestError);
379-
assert.strictEqual(/** @type {RequestError} */(err).message, expectedMessage);
379+
assert.strictEqual(err.message, expectedMessage);
380380

381381
assert.strictEqual(rowCount, 0);
382382

@@ -486,7 +486,7 @@ describe('BulkLoad', function() {
486486
it('does not insert any rows if `cancel` is called immediately after executing the bulk load', function(done) {
487487
const bulkLoad = connection.newBulkLoad('#tmpTestTable5', { keepNulls: true }, (err, rowCount) => {
488488
assert.instanceOf(err, RequestError);
489-
assert.strictEqual(/** @type {RequestError} */(err).message, 'Canceled.');
489+
assert.strictEqual(err.message, 'Canceled.');
490490

491491
assert.isUndefined(rowCount);
492492

@@ -1154,7 +1154,7 @@ describe('BulkLoad', function() {
11541154
*/
11551155
function completeBulkLoad(err, rowCount) {
11561156
assert.instanceOf(err, RequestError);
1157-
assert.strictEqual(/** @type {RequestError} */(err).message, 'Canceled.');
1157+
assert.strictEqual(err.message, 'Canceled.');
11581158

11591159
assert.strictEqual(rowCount, 0);
11601160
startVerifyTableContent();
@@ -1199,7 +1199,7 @@ describe('BulkLoad', function() {
11991199

12001200
const bulkLoad = connection.newBulkLoad('#stream_test', (err, rowCount) => {
12011201
assert.instanceOf(err, RequestError);
1202-
assert.strictEqual(/** @type {RequestError} */(err).message, 'Canceled.');
1202+
assert.strictEqual(err.message, 'Canceled.');
12031203

12041204
assert.strictEqual(rowCount, 0);
12051205
});
@@ -1238,7 +1238,7 @@ describe('BulkLoad', function() {
12381238
it('cancels any bulk load that takes longer than the given timeout', function(done) {
12391239
const bulkLoad = connection.newBulkLoad('#tmpTestTable5', { keepNulls: true }, (err, rowCount) => {
12401240
assert.instanceOf(err, RequestError);
1241-
assert.strictEqual(/** @type {RequestError} */(err).message, 'Timeout: Request failed to complete in 10ms');
1241+
assert.strictEqual(err.message, 'Timeout: Request failed to complete in 10ms');
12421242

12431243
done();
12441244
});
@@ -1339,7 +1339,7 @@ describe('BulkLoad', function() {
13391339
*/
13401340
function completeBulkLoad(err, rowCount) {
13411341
assert.instanceOf(err, RequestError);
1342-
assert.strictEqual(/** @type {RequestError} */(err).message, 'Timeout: Request failed to complete in 200ms');
1342+
assert.strictEqual(err.message, 'Timeout: Request failed to complete in 200ms');
13431343

13441344
assert.strictEqual(rowCount, 0);
13451345

@@ -1526,7 +1526,7 @@ describe('BulkLoad', function() {
15261526
*/
15271527
function completeBulkLoad(err, rowCount) {
15281528
assert.instanceOf(err, TypeError);
1529-
assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.');
1529+
assert.strictEqual(err.message, 'Invalid date.');
15301530

15311531
done();
15321532
}
@@ -1546,7 +1546,7 @@ describe('BulkLoad', function() {
15461546
*/
15471547
function completeBulkLoad(err, rowCount) {
15481548
assert.instanceOf(err, TypeError);
1549-
assert.strictEqual(/** @type {TypeError} */(err).message, 'Invalid date.');
1549+
assert.strictEqual(err.message, 'Invalid date.');
15501550

15511551
assert.strictEqual(rowCount, 0);
15521552

test/integration/connection-test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe('Initiate Connect Test', function() {
290290
const connection = new Connection(config);
291291
connection.connect(function(err) {
292292
assert.instanceOf(err, ConnectionError);
293-
assert.strictEqual(/** @type {ConnectionError} */(err).code, 'ESOCKET');
293+
assert.strictEqual(err.code, 'ESOCKET');
294294
});
295295

296296
connection.on('end', function() {
@@ -385,7 +385,7 @@ describe('Initiate Connect Test', function() {
385385
conn.close();
386386

387387
assert.instanceOf(err, Error);
388-
assert.strictEqual(/** @type {Error} */(err).message, 'Failed to connect to 192.0.2.1:1433 in 3000ms');
388+
assert.strictEqual(err.message, 'Failed to connect to 192.0.2.1:1433 in 3000ms');
389389

390390
done();
391391
});
@@ -867,7 +867,7 @@ describe('Insertion Tests', function() {
867867

868868
const request = new Request('select 8 as C1', function(err, rowCount) {
869869
assert.instanceOf(err, RequestError);
870-
assert.strictEqual(/** @type {RequestError} */(err).code, 'ECLOSE');
870+
assert.strictEqual(err.code, 'ECLOSE');
871871
});
872872

873873
const connection = new Connection(config);
@@ -1202,7 +1202,7 @@ describe('Insertion Tests', function() {
12021202

12031203
const request = new Request("select 1 as C1; waitfor delay '00:00:05'; select 2 as C2", (err, rowCount, rows) => {
12041204
assert.instanceOf(err, Error);
1205-
assert.strictEqual(/** @type {Error} */(err).message, 'Canceled.');
1205+
assert.strictEqual(err.message, 'Canceled.');
12061206

12071207
assert.isUndefined(rowCount);
12081208

@@ -1274,7 +1274,8 @@ describe('Insertion Tests', function() {
12741274
const request = new Request(
12751275
"select 1 as C1;waitfor delay '00:00:05';select 2 as C2",
12761276
function(err, rowCount, rows) {
1277-
assert.equal(/** @type {Error} */(err).message, 'Timeout: Request failed to complete in 1000ms');
1277+
assert.instanceOf(err, RequestError);
1278+
assert.equal(err.message, 'Timeout: Request failed to complete in 1000ms');
12781279

12791280
connection.close();
12801281
}
@@ -1369,9 +1370,9 @@ describe('Advanced Input Test', function() {
13691370
const config = getConfig();
13701371
config.options.enableAnsiNullDefault = false;
13711372

1372-
runSqlBatch(done, config, sql, function(/** @type {Error | null | undefined} */err) {
1373+
runSqlBatch(done, config, sql, function(err) {
13731374
assert.instanceOf(err, RequestError);
1374-
assert.strictEqual(/** @type {RequestError} */(err).number, 515);
1375+
assert.strictEqual(err.number, 515);
13751376
}); // Cannot insert the value NULL
13761377
});
13771378
});

test/integration/errors-test.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ describe('Errors Test', function() {
7070
`;
7171

7272
execSql(done, sql, function(err) {
73-
assert.ok(err instanceof RequestError);
74-
assert.strictEqual(/** @type {RequestError} */(err).number, 2627);
73+
assert.instanceOf(err, RequestError);
74+
assert.strictEqual(err.number, 2627);
7575
});
7676
});
7777

@@ -83,8 +83,8 @@ describe('Errors Test', function() {
8383
`;
8484

8585
execSql(done, sql, function(err) {
86-
assert.ok(err instanceof RequestError);
87-
assert.strictEqual(/** @type {RequestError} */(err).number, 515);
86+
assert.instanceOf(err, RequestError);
87+
assert.strictEqual(err.number, 515);
8888
});
8989
});
9090

@@ -94,8 +94,8 @@ describe('Errors Test', function() {
9494
';
9595

9696
execSql(done, sql, function(err) {
97-
assert.ok(err instanceof RequestError);
98-
assert.strictEqual(/** @type {RequestError} */(err).number, 3701);
97+
assert.instanceOf(err, RequestError);
98+
assert.strictEqual(err.number, 3701);
9999
});
100100
});
101101

@@ -108,24 +108,20 @@ describe('Errors Test', function() {
108108
const connection = new Connection(config);
109109

110110
const execProc = new Request('#testExtendedErrorInfo', function(err) {
111-
if (!err) {
112-
assert.fail('Expected `err` to not be undefined');
113-
}
114-
115-
const requestError = /** @type {RequestError} */(err);
111+
assert.instanceOf(err, RequestError);
116112

117-
assert.strictEqual(requestError.number, 50000);
118-
assert.strictEqual(requestError.state, 42);
119-
assert.strictEqual(requestError.class, 14);
113+
assert.strictEqual(err.number, 50000);
114+
assert.strictEqual(err.state, 42);
115+
assert.strictEqual(err.class, 14);
120116

121-
assert.exists(requestError.serverName);
122-
assert.exists(requestError.procName);
117+
assert.exists(err.serverName);
118+
assert.exists(err.procName);
123119

124120
// The procedure name will actually be padded to 128 chars with underscores and
125121
// some random hexadecimal digits.
126-
assert.match(/** @type {string} */(requestError.procName), /^#testExtendedErrorInfo/);
122+
assert.match(err.procName, /^#testExtendedErrorInfo/);
127123

128-
assert.strictEqual(requestError.lineNumber, 1);
124+
assert.strictEqual(err.lineNumber, 1);
129125

130126
connection.close();
131127
});

test/integration/invalid-packet-stream-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('Connecting to a server that sends invalid packet data', function() {
6060

6161
connection.connect((err) => {
6262
assert.instanceOf(err, ConnectionError);
63-
assert.equal(/** @type {ConnectionError} */(err).message, 'Connection lost - Unable to process incoming packet');
63+
assert.equal(err.message, 'Connection lost - Unable to process incoming packet');
6464

6565
done();
6666
});

test/integration/pause-resume-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe('Pause-Resume Test', function() {
119119

120120
const request = new Request(sql, (error) => {
121121
assert.instanceOf(error, RequestError);
122-
assert.strictEqual(/** @type {RequestError} */(error).code, 'ECANCEL');
122+
assert.strictEqual(error.code, 'ECANCEL');
123123

124124
next();
125125
});

0 commit comments

Comments
 (0)