mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-03 19:51:53 +00:00
chore: use pretty-format types directly in jest typings (#41895)
This commit is contained in:
Vendored
+1
-43
@@ -526,49 +526,7 @@ declare namespace jest {
|
||||
message: () => string;
|
||||
}
|
||||
|
||||
interface SnapshotSerializerOptions {
|
||||
callToJSON?: boolean;
|
||||
edgeSpacing?: string;
|
||||
spacing?: string;
|
||||
escapeRegex?: boolean;
|
||||
highlight?: boolean;
|
||||
indent?: number;
|
||||
maxDepth?: number;
|
||||
min?: boolean;
|
||||
plugins?: SnapshotSerializerPlugin[];
|
||||
printFunctionName?: boolean;
|
||||
theme?: SnapshotSerializerOptionsTheme;
|
||||
|
||||
// see https://github.com/facebook/jest/blob/e56103cf142d2e87542ddfb6bd892bcee262c0e6/types/PrettyFormat.js
|
||||
}
|
||||
interface SnapshotSerializerOptionsTheme {
|
||||
comment?: string;
|
||||
content?: string;
|
||||
prop?: string;
|
||||
tag?: string;
|
||||
value?: string;
|
||||
}
|
||||
interface SnapshotSerializerColor {
|
||||
close: string;
|
||||
open: string;
|
||||
}
|
||||
interface SnapshotSerializerColors {
|
||||
comment: SnapshotSerializerColor;
|
||||
content: SnapshotSerializerColor;
|
||||
prop: SnapshotSerializerColor;
|
||||
tag: SnapshotSerializerColor;
|
||||
value: SnapshotSerializerColor;
|
||||
}
|
||||
interface SnapshotSerializerPlugin {
|
||||
print(
|
||||
val: any,
|
||||
serialize: (val: any) => string,
|
||||
indent: (str: string) => string,
|
||||
opts: SnapshotSerializerOptions,
|
||||
colors: SnapshotSerializerColors
|
||||
): string;
|
||||
test(val: any): boolean;
|
||||
}
|
||||
type SnapshotSerializerPlugin = import('pretty-format').Plugin;
|
||||
|
||||
interface InverseAsymmetricMatchers {
|
||||
/**
|
||||
|
||||
+25
-32
@@ -622,64 +622,57 @@ expect.addSnapshotSerializer({
|
||||
});
|
||||
|
||||
expect.addSnapshotSerializer({
|
||||
print(value, serialize, indent, opts, colors) {
|
||||
serialize(value, config, indentation, depth, refs, printer) {
|
||||
let result = '';
|
||||
|
||||
if (opts.callToJSON !== undefined && opts.callToJSON) {
|
||||
if (config.callToJSON !== undefined && config.callToJSON) {
|
||||
result += ' ';
|
||||
}
|
||||
|
||||
result += opts.edgeSpacing;
|
||||
result += opts.spacing;
|
||||
result += config.spacingInner;
|
||||
result += config.spacingOuter;
|
||||
|
||||
if (opts.escapeRegex !== undefined && opts.escapeRegex) {
|
||||
if (config.escapeRegex !== undefined && config.escapeRegex) {
|
||||
result += ' ';
|
||||
}
|
||||
|
||||
if (opts.indent !== undefined) {
|
||||
for (let i = 0; i < opts.indent; i += 1) {
|
||||
result += '\t';
|
||||
}
|
||||
if (indentation !== undefined) {
|
||||
result += indentation;
|
||||
}
|
||||
|
||||
if (opts.maxDepth !== undefined) {
|
||||
result = result.substring(0, opts.maxDepth);
|
||||
if (config.maxDepth !== undefined) {
|
||||
result = result.substring(0, config.maxDepth);
|
||||
}
|
||||
|
||||
if (opts.min !== undefined && opts.min) {
|
||||
if (config.min !== undefined && config.min) {
|
||||
result += ' ';
|
||||
}
|
||||
|
||||
if (opts.plugins !== undefined) {
|
||||
for (const plugin of opts.plugins) {
|
||||
if (config.plugins !== undefined) {
|
||||
for (const plugin of config.plugins) {
|
||||
expect.addSnapshotSerializer(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
if (opts.printFunctionName !== undefined && opts.printFunctionName) {
|
||||
if (config.printFunctionName !== undefined && config.printFunctionName) {
|
||||
result += ' ';
|
||||
}
|
||||
|
||||
if (opts.theme) {
|
||||
if (opts.theme.comment !== undefined) {
|
||||
result += opts.theme.comment;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
test: (value: {}) => value === value,
|
||||
});
|
||||
|
||||
if (opts.theme.content !== undefined) {
|
||||
result += opts.theme.content;
|
||||
}
|
||||
// old API
|
||||
expect.addSnapshotSerializer({
|
||||
print(value, serialize, indent, opts, colors) {
|
||||
let result = '';
|
||||
|
||||
if (opts.theme.prop !== undefined) {
|
||||
result += opts.theme.prop;
|
||||
}
|
||||
result += opts.edgeSpacing;
|
||||
result += opts.spacing;
|
||||
|
||||
if (opts.theme.tag !== undefined) {
|
||||
result += opts.theme.tag;
|
||||
}
|
||||
|
||||
if (opts.theme.value !== undefined) {
|
||||
result += opts.theme.value;
|
||||
}
|
||||
if (opts.min !== undefined && opts.min) {
|
||||
result += ' ';
|
||||
}
|
||||
|
||||
for (const color of [colors.comment, colors.content, colors.prop, colors.tag, colors.value]) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"jest-diff": "^25.1.0"
|
||||
"jest-diff": "^25.1.0",
|
||||
"pretty-format": "^25.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user