1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 22:58:07 +02:00

Merge pull request #18093 from timvandermeij/exception

Implement a unit test for the `BaseException` class
This commit is contained in:
Tim van der Meij 2024-05-15 13:33:25 +02:00 committed by GitHub
commit 66c2bf62c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,6 +14,7 @@
*/
import {
BaseException,
bytesToString,
createValidAbsoluteUrl,
getModificationDate,
@ -23,6 +24,25 @@ import {
} from "../../src/shared/util.js";
describe("util", function () {
describe("BaseException", function () {
it("can initialize exception classes derived from BaseException", function () {
class DerivedException extends BaseException {
constructor(message) {
super(message, "DerivedException");
this.foo = "bar";
}
}
const exception = new DerivedException("Something went wrong");
expect(exception instanceof DerivedException).toEqual(true);
expect(exception instanceof BaseException).toEqual(true);
expect(exception.message).toEqual("Something went wrong");
expect(exception.name).toEqual("DerivedException");
expect(exception.foo).toEqual("bar");
expect(exception.stack).toContain("BaseExceptionClosure");
});
});
describe("bytesToString", function () {
it("handles non-array arguments", function () {
expect(function () {