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

Bump superstruct to 1.0.3 #71

Merged
merged 2 commits into from Jan 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -33,7 +33,7 @@
"@types/debug": "^4.1.7",
"debug": "^4.3.4",
"semver": "^7.3.8",
"superstruct": "^0.16.7"
"superstruct": "^1.0.3"
},
"devDependencies": {
"@lavamoat/allow-scripts": "^2.0.3",
Expand Down
19 changes: 16 additions & 3 deletions src/assert.test.ts
@@ -1,5 +1,4 @@
import { string } from 'superstruct';
import * as superstructModule from 'superstruct';
import { string, assert as superstructAssert } from 'superstruct';

import {
assert,
Expand All @@ -8,6 +7,11 @@ import {
assertStruct,
} from './assert';

jest.mock('superstruct', () => ({
...jest.requireActual('superstruct'),
assert: jest.fn(),
}));

describe('assert', () => {
it('succeeds', () => {
expect(() => assert(true)).not.toThrow();
Expand Down Expand Up @@ -45,6 +49,13 @@ describe('assertExhaustive', () => {
});

describe('assertStruct', () => {
beforeEach(() => {
const actual = jest.requireActual('superstruct');
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(actual.assert);
});

it('does not throw for a valid value', () => {
expect(() => assertStruct('foo', string())).not.toThrow();
});
Expand Down Expand Up @@ -98,7 +109,9 @@ describe('assertStruct', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'foo.';
});
Expand Down
49 changes: 37 additions & 12 deletions src/json.test.ts
@@ -1,5 +1,4 @@
import * as superstructModule from 'superstruct';
import { validate } from 'superstruct';
import { validate, assert as superstructAssert } from 'superstruct';

import {
assert,
Expand Down Expand Up @@ -36,7 +35,19 @@ import {
NON_SERIALIZABLE_NESTED_OBJECT,
} from './__fixtures__';

jest.mock('superstruct', () => ({
...jest.requireActual('superstruct'),
assert: jest.fn(),
}));

describe('json', () => {
beforeEach(() => {
const actual = jest.requireActual('superstruct');
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(actual.assert);
});

describe('JsonStruct', () => {
it('returns error message', () => {
const [error] = validate(undefined, JsonStruct);
Expand Down Expand Up @@ -104,7 +115,9 @@ describe('json', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
});
Expand Down Expand Up @@ -157,7 +170,9 @@ describe('json', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
});
Expand Down Expand Up @@ -210,9 +225,11 @@ describe('json', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
throw 'oops.';
});

expect(() =>
Expand Down Expand Up @@ -263,9 +280,11 @@ describe('json', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
throw 'oops.';
});

expect(() =>
Expand Down Expand Up @@ -316,7 +335,9 @@ describe('json', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
});
Expand Down Expand Up @@ -361,7 +382,9 @@ describe('json', () => {
);

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
});
Expand Down Expand Up @@ -414,9 +437,11 @@ describe('json', () => {
});

it('includes the value thrown in the message if it is not an error', () => {
jest.spyOn(superstructModule, 'assert').mockImplementation(() => {
(
superstructAssert as jest.MockedFunction<typeof superstructAssert>
).mockImplementation(() => {
// eslint-disable-next-line @typescript-eslint/no-throw-literal
throw 'oops';
throw 'oops.';
});

expect(() =>
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Expand Up @@ -928,7 +928,7 @@ __metadata:
rimraf: ^3.0.2
semver: ^7.3.8
stdio-mock: ^1.2.0
superstruct: ^0.16.7
superstruct: ^1.0.3
ts-jest: ^29.0.3
tsd: ^0.24.1
typedoc: ^0.23.10
Expand Down Expand Up @@ -5934,10 +5934,10 @@ __metadata:
languageName: node
linkType: hard

"superstruct@npm:^0.16.7":
version: 0.16.7
resolution: "superstruct@npm:0.16.7"
checksum: c8c855ff6945da8a41048c6d236de7b1af5d4d9c31742b3ee54d65647c31597488620281f65e095d5efc9e2fbdaad529b8c8f2506c12569d428467c835a21477
"superstruct@npm:^1.0.3":
version: 1.0.3
resolution: "superstruct@npm:1.0.3"
checksum: 761790bb111e6e21ddd608299c252f3be35df543263a7ebbc004e840d01fcf8046794c274bcb351bdf3eae4600f79d317d085cdbb19ca05803a4361840cc9bb1
languageName: node
linkType: hard

Expand Down