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

fix(jest-binary-data-matchers): this.expand may be an undefined value #585

Merged
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
8 changes: 7 additions & 1 deletion packages/jest-matchers/binary-data/src/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { BytesData, bytesEqual, byteSize, isBytesData, padTextColumns, toMessage
import { ensureBytes, ensureByteSizeOrBytes, printBytesDiff } from './utils/jest';
import type { MatcherHintOptions } from './utils/jest';

/**
* The optional property of matcher context is true if undefined.
* @see https://github.com/facebook/jest/blob/v27.0.6/packages/expect/src/matchers.ts#L57-L58
*/
const isExpand = (expand: boolean | undefined): boolean => expand !== false;

function createCompareByteSizeMatcher(
opts: {
matcherName: string;
Expand Down Expand Up @@ -111,7 +117,7 @@ export function toBytesEqual(
printBytesDiff(this.utils, expected, received, {
expectedLabel: 'Expected',
receivedLabel: 'Received',
expand: this.expand,
expand: isExpand(this.expand),
pass,
}),
]);
Expand Down