toBe(Greater|Less)Than
Compare values by their worth
This set of comparisons validate that a value is greater than, less than, or equal to another value. The following assertions are true.
1
// 100 > 42
2
expect(100).toBeGreaterThan(42);
3
4
// 0 < 100
5
expect(0).toBeLessThan(100);
6
7
// 0 !> 100
8
expect(0).not.toBeGreaterThan(100);
9
10
// 1.0 >= 1.0
11
expect(1.0).toBeGreaterThanOrEqual(1.0);
12
13
// 1.0 !<= 0.0
14
expect(1.0).not.toBeLessThanOrEqual(0.0);
Copied!
These assertions also work with reference types when the @operator(">" | "<" | ">=" | "<=") is used on a method in the class.
1
class Vec3 {
2
constructor(public x: f64 = 0.0, public y: f64 = 0.0, public z: f64 = 0.0) {}
3
4
@operator(">")
5
protected __gt(other: Vec3): bool {
6
return (
7
this.x * this.x + this.y * this.y + this.z * this.z >
8
other.x * other.x + other.y * other.y + other.z * other.z
9
);
10
}
11
}
12
13
// valid assertion because `@operator` was overloaded
14
expect(new Vec3(1, 2, 3)).toBeGreaterThan(new Vec3(0, 0, 0));
Copied!
These methods are safe to use portably with jest, provided they aren't used with reference types.
Last modified 1yr ago
Copy link