{
  "id": "fn-test-expect_error",
  "dataComponent": "test",
  "heading": {
    "title": "expect_error",
    "badges": [
      "Testing",
      "Assert"
    ]
  },
  "synopsis": "Expects a user function to raise an error when called, optionally checking that the error message contains a given substring.",
  "codeBlocks": [
    "extend(\"test\")\nextend(\"matrix\")\n\ndescribe(\"Checking dimension mismatch via expect_error\", () => {\n\n  it(\"should raise an error with no substring check\", () => {\n    test:expect_error(() => {\n      # Attempt dimension mismatch => matrix:multiply => triggers error\n      matrix:multiply([[1,2,3],[4,5,6]], [[7,8],[9,10]])\n    })\n  })\n\n  it(\"should raise an error containing 'dimension mismatch'\", () => {\n    test:expect_error(\n      () => {\n        matrix:multiply([[1,2],[3,4,5]], [[7,8],[9,10]])\n      },\n      \"dimension mismatch\"\n    )\n  })\n\n})"
  ],
  "notes": [
    "Takes 1 or 2 arguments:",
    "- First argument: a function with no parameters, which we call expecting it to fail.",
    "- Second argument (optional): a string. If present, we check that the error message contains this substring.",
    "If the user function does NOT raise an error, the current test fails immediately. If it raises an error but does not contain the optional substring, the test fails too.",
    "If an error occurs and matches the optional substring (or no substring was provided), the test is considered passed for that scenario."
  ]
}
