constructor()

in packages/sqrl/src/testing/Assert.ts [107:164]


  constructor(actual, expected, ...msg: any[]) {
    const assertions = [new TypeAssertion(actual, expected)];

    if (assertions.every((a) => a.result)) {
      if (Array.isArray(actual)) {
        assertions.push(
          new OpAssertion(
            actual.length,
            expected.length,
            "===",
            "%d === %d (length mismatch)",
            actual.length,
            expected.length
          )
        );
        if (assertions.every((a) => a.result)) {
          assertions.push(
            ...actual.map((value, idx) => {
              return new DeepEqualAssertion(
                value,
                expected[idx],
                "actual[%d] (=) expected[%d]",
                idx,
                idx
              );
            })
          );
        }
      } else if (actual !== expected && typeof actual === "object") {
        assertions.push(
          new DeepEqualAssertion(
            Object.keys(actual).sort(),
            Object.keys(expected).sort(),
            "keys(actual) (=) keys(expected)"
          )
        );
        if (assertions.every((a) => a.result)) {
          assertions.push(
            ...Object.keys(actual).map((key) => {
              return new DeepEqualAssertion(
                actual[key],
                expected[key],
                "actual[%j] (=) expected[%j]",
                key,
                key
              );
            })
          );
        }
      } else {
        assertions.push(new OpAssertion(actual, expected, "==="));
      }
    }

    super(assertions, ...msg);
    this.actual = actual;
    this.expected = expected;
  }