版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

173 lines
7.3 KiB

  1. import { use } from 'chai';
  2. import { stringify } from '@vitest/utils';
  3. export { setupColors } from '@vitest/utils';
  4. type Formatter = (input: string | number | null | undefined) => string;
  5. declare function getMatcherUtils(): {
  6. EXPECTED_COLOR: (input: unknown) => string;
  7. RECEIVED_COLOR: (input: unknown) => string;
  8. INVERTED_COLOR: (input: unknown) => string;
  9. BOLD_WEIGHT: (input: unknown) => string;
  10. DIM_COLOR: (input: unknown) => string;
  11. matcherHint: (matcherName: string, received?: string, expected?: string, options?: MatcherHintOptions) => string;
  12. printReceived: (object: unknown) => string;
  13. printExpected: (value: unknown) => string;
  14. };
  15. declare function diff(a: any, b: any, options?: DiffOptions): string;
  16. type FirstFunctionArgument<T> = T extends (arg: infer A) => unknown ? A : never;
  17. type ChaiPlugin = FirstFunctionArgument<typeof use>;
  18. type Tester = (a: any, b: any) => boolean | undefined;
  19. interface MatcherHintOptions {
  20. comment?: string;
  21. expectedColor?: Formatter;
  22. isDirectExpectCall?: boolean;
  23. isNot?: boolean;
  24. promise?: string;
  25. receivedColor?: Formatter;
  26. secondArgument?: string;
  27. secondArgumentColor?: Formatter;
  28. }
  29. interface DiffOptions {
  30. aAnnotation?: string;
  31. aColor?: Formatter;
  32. aIndicator?: string;
  33. bAnnotation?: string;
  34. bColor?: Formatter;
  35. bIndicator?: string;
  36. changeColor?: Formatter;
  37. changeLineTrailingSpaceColor?: Formatter;
  38. commonColor?: Formatter;
  39. commonIndicator?: string;
  40. commonLineTrailingSpaceColor?: Formatter;
  41. contextLines?: number;
  42. emptyFirstOrLastLinePlaceholder?: string;
  43. expand?: boolean;
  44. includeChangeCounts?: boolean;
  45. omitAnnotationLines?: boolean;
  46. patchColor?: Formatter;
  47. compareKeys?: any;
  48. showLegend?: boolean;
  49. }
  50. interface MatcherState {
  51. assertionCalls: number;
  52. currentTestName?: string;
  53. dontThrow?: () => void;
  54. error?: Error;
  55. equals: (a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean) => boolean;
  56. expand?: boolean;
  57. expectedAssertionsNumber?: number | null;
  58. expectedAssertionsNumberErrorGen?: (() => Error) | null;
  59. isExpectingAssertions?: boolean;
  60. isExpectingAssertionsError?: Error | null;
  61. isNot: boolean;
  62. promise: string;
  63. suppressedErrors: Array<Error>;
  64. testPath?: string;
  65. utils: ReturnType<typeof getMatcherUtils> & {
  66. diff: typeof diff;
  67. stringify: typeof stringify;
  68. iterableEquality: Tester;
  69. subsetEquality: Tester;
  70. };
  71. }
  72. interface SyncExpectationResult {
  73. pass: boolean;
  74. message: () => string;
  75. actual?: any;
  76. expected?: any;
  77. }
  78. type AsyncExpectationResult = Promise<SyncExpectationResult>;
  79. type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;
  80. interface RawMatcherFn<T extends MatcherState = MatcherState> {
  81. (this: T, received: any, expected: any, options?: any): ExpectationResult;
  82. }
  83. type MatchersObject<T extends MatcherState = MatcherState> = Record<string, RawMatcherFn<T>>;
  84. interface AsymmetricMatcherInterface {
  85. asymmetricMatch(other: unknown): boolean;
  86. toString(): string;
  87. getExpectedType?(): string;
  88. toAsymmetricMatcher?(): string;
  89. }
  90. declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
  91. protected sample: T;
  92. protected inverse: boolean;
  93. $$typeof: symbol;
  94. constructor(sample: T, inverse?: boolean);
  95. protected getMatcherContext(expect?: Vi.ExpectStatic): State;
  96. abstract asymmetricMatch(other: unknown): boolean;
  97. abstract toString(): string;
  98. getExpectedType?(): string;
  99. toAsymmetricMatcher?(): string;
  100. }
  101. declare class StringContaining extends AsymmetricMatcher<string> {
  102. constructor(sample: string, inverse?: boolean);
  103. asymmetricMatch(other: string): boolean;
  104. toString(): string;
  105. getExpectedType(): string;
  106. }
  107. declare class Anything extends AsymmetricMatcher<void> {
  108. asymmetricMatch(other: unknown): boolean;
  109. toString(): string;
  110. toAsymmetricMatcher(): string;
  111. }
  112. declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
  113. constructor(sample: Record<string, unknown>, inverse?: boolean);
  114. getPrototype(obj: object): any;
  115. hasProperty(obj: object | null, property: string): boolean;
  116. asymmetricMatch(other: any): boolean;
  117. toString(): string;
  118. getExpectedType(): string;
  119. }
  120. declare class ArrayContaining<T = unknown> extends AsymmetricMatcher<Array<T>> {
  121. constructor(sample: Array<T>, inverse?: boolean);
  122. asymmetricMatch(other: Array<T>): boolean;
  123. toString(): string;
  124. getExpectedType(): string;
  125. }
  126. declare class Any extends AsymmetricMatcher<any> {
  127. constructor(sample: unknown);
  128. fnNameFor(func: Function): string;
  129. asymmetricMatch(other: unknown): boolean;
  130. toString(): string;
  131. getExpectedType(): string;
  132. toAsymmetricMatcher(): string;
  133. }
  134. declare class StringMatching extends AsymmetricMatcher<RegExp> {
  135. constructor(sample: string | RegExp, inverse?: boolean);
  136. asymmetricMatch(other: string): boolean;
  137. toString(): string;
  138. getExpectedType(): string;
  139. }
  140. declare const JestAsymmetricMatchers: ChaiPlugin;
  141. declare function equals(a: unknown, b: unknown, customTesters?: Array<Tester>, strictCheck?: boolean): boolean;
  142. declare function isAsymmetric(obj: any): boolean;
  143. declare function hasAsymmetric(obj: any, seen?: Set<unknown>): boolean;
  144. declare function isA(typeName: string, value: unknown): boolean;
  145. declare function fnNameFor(func: Function): string;
  146. declare function hasProperty(obj: object | null, property: string): boolean;
  147. declare function isImmutableUnorderedKeyed(maybeKeyed: any): boolean;
  148. declare function isImmutableUnorderedSet(maybeSet: any): boolean;
  149. declare const iterableEquality: (a: any, b: any, aStack?: Array<any>, bStack?: Array<any>) => boolean | undefined;
  150. declare const subsetEquality: (object: unknown, subset: unknown) => boolean | undefined;
  151. declare const typeEquality: (a: any, b: any) => boolean | undefined;
  152. declare const arrayBufferEquality: (a: unknown, b: unknown) => boolean | undefined;
  153. declare const sparseArrayEquality: (a: unknown, b: unknown) => boolean | undefined;
  154. declare const generateToBeMessage: (deepEqualityName: string, expected?: string, actual?: string) => string;
  155. declare const MATCHERS_OBJECT: unique symbol;
  156. declare const JEST_MATCHERS_OBJECT: unique symbol;
  157. declare const GLOBAL_EXPECT: unique symbol;
  158. declare const getState: <State extends MatcherState = MatcherState>(expect: Vi.ExpectStatic) => State;
  159. declare const setState: <State extends MatcherState = MatcherState>(state: Partial<State>, expect: Vi.ExpectStatic) => void;
  160. declare const JestChaiExpect: ChaiPlugin;
  161. declare const JestExtend: ChaiPlugin;
  162. export { Any, Anything, ArrayContaining, AsymmetricMatcher, AsymmetricMatcherInterface, AsyncExpectationResult, ChaiPlugin, DiffOptions, ExpectationResult, FirstFunctionArgument, GLOBAL_EXPECT, JEST_MATCHERS_OBJECT, JestAsymmetricMatchers, JestChaiExpect, JestExtend, MATCHERS_OBJECT, MatcherHintOptions, MatcherState, MatchersObject, ObjectContaining, RawMatcherFn, StringContaining, StringMatching, SyncExpectationResult, Tester, arrayBufferEquality, equals, fnNameFor, generateToBeMessage, getState, hasAsymmetric, hasProperty, isA, isAsymmetric, isImmutableUnorderedKeyed, isImmutableUnorderedSet, iterableEquality, setState, sparseArrayEquality, subsetEquality, typeEquality };