asymmetricMatchers.d.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. */
  8. import type { AsymmetricMatcher as AsymmetricMatcherInterface, MatcherState } from './types';
  9. export declare abstract class AsymmetricMatcher<T, State extends MatcherState = MatcherState> implements AsymmetricMatcherInterface {
  10. protected sample: T;
  11. protected inverse: boolean;
  12. $$typeof: symbol;
  13. constructor(sample: T, inverse?: boolean);
  14. protected getMatcherContext(): State;
  15. abstract asymmetricMatch(other: unknown): boolean;
  16. abstract toString(): string;
  17. getExpectedType?(): string;
  18. toAsymmetricMatcher?(): string;
  19. }
  20. declare class Any extends AsymmetricMatcher<any> {
  21. constructor(sample: unknown);
  22. asymmetricMatch(other: unknown): boolean;
  23. toString(): string;
  24. getExpectedType(): string;
  25. toAsymmetricMatcher(): string;
  26. }
  27. declare class Anything extends AsymmetricMatcher<void> {
  28. asymmetricMatch(other: unknown): boolean;
  29. toString(): string;
  30. toAsymmetricMatcher(): string;
  31. }
  32. declare class ArrayContaining extends AsymmetricMatcher<Array<unknown>> {
  33. constructor(sample: Array<unknown>, inverse?: boolean);
  34. asymmetricMatch(other: Array<unknown>): boolean;
  35. toString(): string;
  36. getExpectedType(): string;
  37. }
  38. declare class ObjectContaining extends AsymmetricMatcher<Record<string, unknown>> {
  39. constructor(sample: Record<string, unknown>, inverse?: boolean);
  40. asymmetricMatch(other: any): boolean;
  41. toString(): string;
  42. getExpectedType(): string;
  43. }
  44. declare class StringContaining extends AsymmetricMatcher<string> {
  45. constructor(sample: string, inverse?: boolean);
  46. asymmetricMatch(other: string): boolean;
  47. toString(): string;
  48. getExpectedType(): string;
  49. }
  50. declare class StringMatching extends AsymmetricMatcher<RegExp> {
  51. constructor(sample: string | RegExp, inverse?: boolean);
  52. asymmetricMatch(other: string): boolean;
  53. toString(): string;
  54. getExpectedType(): string;
  55. }
  56. declare class CloseTo extends AsymmetricMatcher<number> {
  57. private precision;
  58. constructor(sample: number, precision?: number, inverse?: boolean);
  59. asymmetricMatch(other: number): boolean;
  60. toString(): string;
  61. getExpectedType(): string;
  62. }
  63. export declare const any: (expectedObject: unknown) => Any;
  64. export declare const anything: () => Anything;
  65. export declare const arrayContaining: (sample: Array<unknown>) => ArrayContaining;
  66. export declare const arrayNotContaining: (sample: Array<unknown>) => ArrayContaining;
  67. export declare const objectContaining: (sample: Record<string, unknown>) => ObjectContaining;
  68. export declare const objectNotContaining: (sample: Record<string, unknown>) => ObjectContaining;
  69. export declare const stringContaining: (expected: string) => StringContaining;
  70. export declare const stringNotContaining: (expected: string) => StringContaining;
  71. export declare const stringMatching: (expected: string | RegExp) => StringMatching;
  72. export declare const stringNotMatching: (expected: string | RegExp) => StringMatching;
  73. export declare const closeTo: (expected: number, precision?: number | undefined) => CloseTo;
  74. export declare const notCloseTo: (expected: number, precision?: number | undefined) => CloseTo;
  75. export {};