Skip to content

Commit 7f9372c

Browse files
Update TEST_FORMAT.md
1 parent 4cdce3b commit 7f9372c

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

TEST_FORMAT.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,21 @@ A test case should be a JSON object with the following fields:
99
- **`description`** *(string, required)*: A short, human-readable description of the test case that explains its purpose.
1010
- **`rule`** *(any, required)*: The JSON Logic rule to be tested.
1111
- **`data`** *(any, required)*: The input data that the rule will evaluate against.
12+
13+
And either:
14+
1215
- **`result`** *(any, required)*: The expected result after evaluating the rule with the provided data.
1316

17+
OR
18+
19+
- **`error`** *(Partial\<Error\>, required)* - Communicates that it is expected that the logic will fail due to a hard error. This object must partial match against the error emitted.
20+
1421
`any` refers to any valid [RFC8259](https://datatracker.ietf.org/doc/html/rfc8259) value.
1522

1623
`string` refers to [strings in RFC8259](https://datatracker.ietf.org/doc/html/rfc8259#section-7).
1724

25+
`Error`, at this time, is defined as a JSON Object with a `type` property, defined as a string (e.g. `{ "type": "NaN" }`).
26+
1827
The test cases are stored as an array of these objects, allowing for multiple tests in a single file.
1928

2029
## Example Test Cases
@@ -74,6 +83,25 @@ Below are examples demonstrating how to format JSON Logic test cases:
7483
]
7584
```
7685

86+
### Error Logic Test
87+
88+
```json
89+
[
90+
{
91+
"description": "Checks if division by zero fails",
92+
"rule": { "/": [0, 0] },
93+
"error": { "type": "NaN" },
94+
"data": null
95+
},
96+
{
97+
"description": "Checks if throw can be embedded in another operator",
98+
"rule": { "+": [1, { "throw": "Some error" }] },
99+
"error": { "type": "Some error" },
100+
"data": null
101+
}
102+
]
103+
```
104+
77105
## Commentary and Section Headers
78106

79107
Strings in the root array will be ignored by the JSON Logic test processor. This allows you to add comments or declare section headers to provide human-readable information in your test-suite.

0 commit comments

Comments
 (0)