Skip to content

Commit

Permalink
Merge pull request #88 from Procedure-RPC/disable-jest-globals
Browse files Browse the repository at this point in the history
Explicitly import jest globals
  • Loading branch information
toebeann committed Nov 1, 2022
2 parents 516847f + ec5dc4b commit cb5c85a
Show file tree
Hide file tree
Showing 4 changed files with 820 additions and 477 deletions.
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

0 comments on commit cb5c85a

Please sign in to comment.