Skip to content

Commit 1d84d3b

Browse files
committed
docs(expect): add .not negation modifier documentation
Document the .not modifier behavior where it only affects the immediately following assertion and then resets to non-negated state.
1 parent b911ded commit 1d84d3b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/expect.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ export default scenario("Assertion Example")
3636
.build();
3737
```
3838

39+
## Negation with `.not`
40+
41+
All expectation types support the `.not` modifier to negate assertions. The
42+
`.not` modifier only affects the immediately following assertion, then resets to
43+
non-negated state:
44+
45+
```typescript
46+
import { client, expect } from "jsr:@probitas/probitas";
47+
48+
const http = client.http.createHttpClient({ url: "http://localhost:8080" });
49+
const res = await http.get("/users/1");
50+
51+
// .not only affects the next assertion
52+
expect(res)
53+
.not.toHaveStatus(404) // Negated: status is NOT 404
54+
.not.toHaveStatus(500) // Negated: status is NOT 500
55+
.toHaveStatus(200); // Not negated: status IS 200
56+
57+
// Works with generic expectations too
58+
expect(42)
59+
.not.toBe(43) // Negated
60+
.toBeGreaterThan(40); // Not negated
61+
62+
expect("hello world")
63+
.not.toBe("goodbye")
64+
.not.toBeNull()
65+
.toContain("world");
66+
```
67+
3968
## Unified expect Function
4069

4170
The [`expect()`](/api/expect/#expect) function automatically dispatches to the

0 commit comments

Comments
 (0)