|
1 | 1 | import { pipe } from "rambda"; |
2 | 2 | import { Ok, Err, fromThrowable, fromPromise, fromAsync, matchR, mapR, unwrapOrR, chainR, mapErrR } from "../src/result"; |
| 3 | +import { equalsR } from "../src/result/Result"; |
3 | 4 |
|
4 | 5 | describe("Result", () => { |
5 | 6 | it("Ok.map should apply the function", () => { |
@@ -69,6 +70,30 @@ describe("Result", () => { |
69 | 70 | expect(result.isErr()).toBe(true); |
70 | 71 | expect(result.isOk()).toBe(false); |
71 | 72 | }); |
| 73 | + |
| 74 | + it("Ok.equals should be equal to another Ok with same value", () => { |
| 75 | + const result1 = new Ok(5); |
| 76 | + const result2 = new Ok(5); |
| 77 | + expect(result1.equals(result2)).toBe(true); |
| 78 | + }); |
| 79 | + |
| 80 | + it("Err.equals should be equal to another Err with same error", () => { |
| 81 | + const result1 = new Err("error"); |
| 82 | + const result2 = new Err("error"); |
| 83 | + expect(result1.equals(result2)).toBe(true); |
| 84 | + }); |
| 85 | + |
| 86 | + it("Ok.equals should not be equal to Err", () => { |
| 87 | + const result1 = new Ok(5); |
| 88 | + const result2 = new Err<number, string>("error"); |
| 89 | + expect(result1.equals(result2)).toBe(false); |
| 90 | + }); |
| 91 | + |
| 92 | + it("Err.equals should not be equal to Ok", () => { |
| 93 | + const result1 = new Err("error"); |
| 94 | + const result2 = new Ok<number, string>(5); |
| 95 | + expect(result1.equals(result2)).toBe(false); |
| 96 | + }); |
72 | 97 | }); |
73 | 98 |
|
74 | 99 | describe("Result fromThrowable", () => { |
@@ -257,4 +282,36 @@ describe("Result - Curried Helpers", () => { |
257 | 282 | ); |
258 | 283 | expect(result).toBe("Error: Something went wrong"); |
259 | 284 | }); |
| 285 | + |
| 286 | + it("should equals with another Ok using curried equals", () => { |
| 287 | + const result = pipe( |
| 288 | + new Ok(5), |
| 289 | + equalsR(new Ok(5)) |
| 290 | + ); |
| 291 | + expect(result).toBe(true); |
| 292 | + }); |
| 293 | + |
| 294 | + it("should not equals with another Ok using curried equals", () => { |
| 295 | + const result = pipe( |
| 296 | + new Ok(5), |
| 297 | + equalsR(new Ok(10)) |
| 298 | + ); |
| 299 | + expect(result).toBe(false); |
| 300 | + }); |
| 301 | + |
| 302 | + it("should equals with another Err using curried equals", () => { |
| 303 | + const result = pipe( |
| 304 | + new Err("Error"), |
| 305 | + equalsR(new Err("Error")) |
| 306 | + ); |
| 307 | + expect(result).toBe(true); |
| 308 | + }); |
| 309 | + |
| 310 | + it("should not equals with another Err using curried equals", () => { |
| 311 | + const result = pipe( |
| 312 | + new Err("Error"), |
| 313 | + equalsR(new Err("Different Error")) |
| 314 | + ); |
| 315 | + expect(result).toBe(false); |
| 316 | + }); |
260 | 317 | }); |
0 commit comments