Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly import jest globals #88

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"preset": "ts-jest",
"injectGlobals": false,
"restoreMocks": true,
"testEnvironment": "node",
"coverageReporters": ["html", "text", "cobertura", "json", "lcovonly"],
"coverageThreshold": {
Expand Down
115 changes: 0 additions & 115 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 51 additions & 25 deletions test/errors.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { beforeEach, describe, expect, it } from '@jest/globals';

import {
ProcedureError,
ProcedureUnknownError,
Expand Down Expand Up @@ -104,7 +106,9 @@ describe('ProcedureInternalClientError', () => {
let instance: ProcedureInternalClientError;

describe('when no parameters passed', () => {
beforeEach(() => (instance = new ProcedureInternalClientError()));
beforeEach(() => {
instance = new ProcedureInternalClientError();
});

it('should be: instanceof ProcedureError', () => {
expect(instance).toBeInstanceOf(ProcedureError);
Expand Down Expand Up @@ -725,35 +729,45 @@ describe('isError(object: unknown): object is Error', () => {
});

describe('when object: undefined', () => {
beforeEach(() => (object = undefined));
beforeEach(() => {
object = undefined;
});
it('should return: false', () => {
expect(isError(object)).toEqual(false);
});
});

describe('when object: null', () => {
beforeEach(() => (object = null));
beforeEach(() => {
object = null;
});
it('should return: false', () => {
expect(isError(object)).toEqual(false);
});
});

describe('when object: instanceof TypeError', () => {
beforeEach(() => (object = new TypeError()));
beforeEach(() => {
object = new TypeError();
});
it('should return: true', () => {
expect(isError(object)).toEqual(true);
});
});

describe("when object: { name: 'Foo', message: 'Bar' }", () => {
beforeEach(() => (object = { name: 'Foo', message: 'Bar' }));
beforeEach(() => {
object = { name: 'Foo', message: 'Bar' };
});
it('should return: true', () => {
expect(isError(object)).toEqual(true);
});
});

describe("when object: { name: 'Foo' }", () => {
beforeEach(() => (object = { name: 'Foo' }));
beforeEach(() => {
object = { name: 'Foo' };
});
it('should return: false', () => {
expect(isError(object)).toEqual(false);
});
Expand All @@ -763,73 +777,85 @@ describe('isError(object: unknown): object is Error', () => {
describe('isProcedureError(object: unknown): object is ProcedureError', () => {
let object: unknown;
describe('when object: instanceof Error', () => {
beforeEach(() => (object = new Error()));
beforeEach(() => {
object = new Error();
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
});

describe('when object: undefined', () => {
beforeEach(() => (object = undefined));
beforeEach(() => {
object = undefined;
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
});

describe('when object: null', () => {
beforeEach(() => (object = null));
beforeEach(() => {
object = null;
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
});

describe('when object: instanceof TypeError', () => {
beforeEach(() => (object = new TypeError()));
beforeEach(() => {
object = new TypeError();
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
});

describe("when object: { name: 'Foo', message: 'Bar' }", () => {
beforeEach(() => (object = { name: 'Foo', message: 'Bar' }));
beforeEach(() => {
object = { name: 'Foo', message: 'Bar' };
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
});

describe("when object: { name: 'Foo' }", () => {
beforeEach(() => (object = { name: 'Foo' }));
beforeEach(() => {
object = { name: 'Foo' };
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
});

describe('when object: instanceof ProcedureError', () => {
beforeEach(() => (object = new ProcedureUnknownError()));
beforeEach(() => {
object = new ProcedureUnknownError();
});
it('should return: true', () => {
expect(isProcedureError(object)).toEqual(true);
});
});

describe("when object: { name: 'ProcedureError', message: 'foo', code: ProcedureErrorCodes.NOT_FOUND }", () => {
beforeEach(
() =>
(object = {
name: 'ProcedureError',
message: 'foo',
code: ProcedureErrorCodes.NOT_FOUND,
})
);
beforeEach(() => {
object = {
name: 'ProcedureError',
message: 'foo',
code: ProcedureErrorCodes.NOT_FOUND,
};
});
it('should return: true', () => {
expect(isProcedureError(object)).toEqual(true);
});
});

describe("when object: { name: 'ProcedureError', message: 'foo', code: -1 }", () => {
beforeEach(
() =>
(object = { name: 'ProcedureError', message: 'foo', code: -1 })
);
beforeEach(() => {
object = { name: 'ProcedureError', message: 'foo', code: -1 };
});
it('should return: false', () => {
expect(isProcedureError(object)).toEqual(false);
});
Expand Down
Loading