Skip to content

Commit 7609a42

Browse files
committed
Use toBeInstanceOf consistently in the unit-tests
There's currently a lot of unit-tests that manually check `instanceof`, let's replace that with the built-in Jasmine matcher function; see https://jasmine.github.io/api/edge/matchers.html#toBeInstanceOf
1 parent bda7456 commit 7609a42

13 files changed

Lines changed: 152 additions & 156 deletions

test/unit/api_spec.js

Lines changed: 123 additions & 127 deletions
Large diffs are not rendered by default.

test/unit/canvas_factory_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ describe("canvas_factory", function () {
4646
}
4747

4848
const { canvas, context } = canvasFactory.create(20, 40);
49-
expect(canvas instanceof HTMLCanvasElement).toBe(true);
50-
expect(context instanceof CanvasRenderingContext2D).toBe(true);
49+
expect(canvas).toBeInstanceOf(HTMLCanvasElement);
50+
expect(context).toBeInstanceOf(CanvasRenderingContext2D);
5151
expect(canvas.width).toBe(20);
5252
expect(canvas.height).toBe(40);
5353
});
@@ -83,8 +83,8 @@ describe("canvas_factory", function () {
8383
canvasFactory.reset(canvasAndContext, 60, 80);
8484

8585
const { canvas, context } = canvasAndContext;
86-
expect(canvas instanceof HTMLCanvasElement).toBe(true);
87-
expect(context instanceof CanvasRenderingContext2D).toBe(true);
86+
expect(canvas).toBeInstanceOf(HTMLCanvasElement);
87+
expect(context).toBeInstanceOf(CanvasRenderingContext2D);
8888
expect(canvas.width).toBe(60);
8989
expect(canvas.height).toBe(80);
9090
});

test/unit/cmap_spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ describe("cmap", function () {
139139
fetchBuiltInCMap,
140140
useCMap: null,
141141
});
142-
expect(cmap instanceof CMap).toEqual(true);
142+
expect(cmap).toBeInstanceOf(CMap);
143143
expect(cmap.useCMap).not.toBeNull();
144144
expect(cmap.builtInCMap).toBeFalsy();
145145
expect(cmap.length).toEqual(0x20a7);
@@ -166,7 +166,7 @@ describe("cmap", function () {
166166
fetchBuiltInCMap,
167167
useCMap: null,
168168
});
169-
expect(cmap instanceof CMap).toEqual(true);
169+
expect(cmap).toBeInstanceOf(CMap);
170170
expect(cmap.useCMap).toBeNull();
171171
expect(cmap.builtInCMap).toBeTruthy();
172172
expect(cmap.length).toEqual(0x20a7);
@@ -179,7 +179,7 @@ describe("cmap", function () {
179179
fetchBuiltInCMap,
180180
useCMap: null,
181181
});
182-
expect(cmap instanceof IdentityCMap).toEqual(true);
182+
expect(cmap).toBeInstanceOf(IdentityCMap);
183183
expect(cmap.vertical).toEqual(false);
184184
expect(cmap.length).toEqual(0x10000);
185185
expect(function () {
@@ -198,7 +198,7 @@ describe("cmap", function () {
198198
// Shouldn't get here.
199199
expect(false).toEqual(true);
200200
} catch (reason) {
201-
expect(reason instanceof Error).toEqual(true);
201+
expect(reason).toBeInstanceOf(Error);
202202
expect(reason.message).toEqual("Unknown CMap name: null");
203203
}
204204
});
@@ -219,7 +219,7 @@ describe("cmap", function () {
219219
// Shouldn't get here.
220220
expect(false).toEqual(true);
221221
} catch (reason) {
222-
expect(reason instanceof Error).toEqual(true);
222+
expect(reason).toBeInstanceOf(Error);
223223
expect(reason.message).toEqual(
224224
"Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided."
225225
);
@@ -245,7 +245,7 @@ describe("cmap", function () {
245245
// Shouldn't get here.
246246
expect(false).toEqual(true);
247247
} catch (reason) {
248-
expect(reason instanceof Error).toEqual(true);
248+
expect(reason).toBeInstanceOf(Error);
249249
const message = reason.message;
250250
expect(message.startsWith("Unable to load CMap at: ")).toEqual(true);
251251
expect(message.endsWith("/external/bcmaps/Adobe-Japan1-1")).toEqual(true);

test/unit/crypto_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ describe("CipherTransformFactory", function () {
565565
// Shouldn't get here.
566566
expect(false).toEqual(true);
567567
} catch (ex) {
568-
expect(ex instanceof PasswordException).toEqual(true);
568+
expect(ex).toBeInstanceOf(PasswordException);
569569
expect(ex.code).toEqual(PasswordResponses.NEED_PASSWORD);
570570
}
571571
}
@@ -578,7 +578,7 @@ describe("CipherTransformFactory", function () {
578578
// Shouldn't get here.
579579
expect(false).toEqual(true);
580580
} catch (ex) {
581-
expect(ex instanceof PasswordException).toEqual(true);
581+
expect(ex).toBeInstanceOf(PasswordException);
582582
expect(ex.code).toEqual(PasswordResponses.INCORRECT_PASSWORD);
583583
}
584584
}

test/unit/evaluator_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ describe("evaluator", function () {
296296
// Shouldn't get here.
297297
expect(false).toEqual(true);
298298
} catch (reason) {
299-
expect(reason instanceof FormatError).toEqual(true);
299+
expect(reason).toBeInstanceOf(FormatError);
300300
expect(reason.message).toEqual(
301301
"Invalid command l: expected 2 args, but received 1 args."
302302
);
@@ -332,7 +332,7 @@ describe("evaluator", function () {
332332
// Shouldn't get here.
333333
expect(false).toEqual(true);
334334
} catch (reason) {
335-
expect(reason instanceof FormatError).toEqual(true);
335+
expect(reason).toBeInstanceOf(FormatError);
336336
expect(reason.message).toEqual("XObject should be a stream");
337337
}
338338
});

test/unit/event_utils_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ describe("event_utils", function () {
243243
expect(false).toEqual(true);
244244
},
245245
function (reason) {
246-
expect(reason instanceof Error).toEqual(true);
246+
expect(reason).toBeInstanceOf(Error);
247247
}
248248
);
249249

@@ -256,7 +256,7 @@ describe("event_utils", function () {
256256
expect(false).toEqual(true);
257257
},
258258
function (reason) {
259-
expect(reason instanceof Error).toEqual(true);
259+
expect(reason).toBeInstanceOf(Error);
260260
}
261261
);
262262

@@ -270,7 +270,7 @@ describe("event_utils", function () {
270270
expect(false).toEqual(true);
271271
},
272272
function (reason) {
273-
expect(reason instanceof Error).toEqual(true);
273+
expect(reason).toBeInstanceOf(Error);
274274
}
275275
);
276276

test/unit/message_handler_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe("message_handler", function () {
194194
expect(false).toEqual(true);
195195
} catch (reason) {
196196
expect(log).toEqual("01pe");
197-
expect(reason instanceof UnknownErrorException).toEqual(true);
197+
expect(reason).toBeInstanceOf(UnknownErrorException);
198198
expect(reason.message).toEqual("should not read when errored");
199199
}
200200
});

test/unit/network_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ describe("network", function () {
155155
// Shouldn't get here.
156156
expect(false).toEqual(true);
157157
} catch (ex) {
158-
expect(ex instanceof ResponseException).toEqual(true);
158+
expect(ex).toBeInstanceOf(ResponseException);
159159
expect(ex.status).toEqual(0);
160160
expect(ex.missing).toEqual(false);
161161
}

test/unit/network_utils_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ describe("network_utils", function () {
370370
function testCreateResponseError(url, status, missing) {
371371
const error = createResponseError(status, url);
372372

373-
expect(error instanceof ResponseException).toEqual(true);
373+
expect(error).toBeInstanceOf(ResponseException);
374374
expect(error.message).toEqual(
375375
`Unexpected server response (${status}) while retrieving PDF "${url.href}".`
376376
);

test/unit/parser_spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,15 +240,15 @@ describe("parser", function () {
240240
const lexer = new Lexer(input);
241241

242242
let obj = lexer.getObj();
243-
expect(obj instanceof Cmd).toEqual(true);
243+
expect(obj).toBeInstanceOf(Cmd);
244244
expect(obj.cmd).toEqual("\x14");
245245

246246
obj = lexer.getObj();
247-
expect(obj instanceof Cmd).toEqual(true);
247+
expect(obj).toBeInstanceOf(Cmd);
248248
expect(obj.cmd).toEqual("q");
249249

250250
obj = lexer.getObj();
251-
expect(obj instanceof Cmd).toEqual(true);
251+
expect(obj).toBeInstanceOf(Cmd);
252252
expect(obj.cmd).toEqual("Q");
253253

254254
obj = lexer.getObj();

0 commit comments

Comments
 (0)