|
| 1 | +import {expectType} from "ts-expect"; |
| 2 | +import {GreaterThanOrEqualMatcher} from "../../../../src/matcher/type/number/GreaterThanOrEqualMatcher"; |
| 3 | +import {greaterThanOrEqual, imock, instance, when} from "../../../../src/ts-mockito"; |
| 4 | + |
| 5 | +describe("GreaterThanOrEqualMatcher", () => { |
| 6 | + describe("greaterThanOrEqual()", () => { |
| 7 | + it("should be a IfAfterOrEqualMatcher instance", () => { |
| 8 | + expect((greaterThanOrEqual(0) as any) instanceof GreaterThanOrEqualMatcher).toBe(true); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should be a number type", () => { |
| 12 | + expectType<number>(greaterThanOrEqual(0)); |
| 13 | + }); |
| 14 | + }); |
| 15 | + |
| 16 | + describe("#match()", () => { |
| 17 | + it("should return true when the given number is greater than the expected number", () => { |
| 18 | + const matcher = new GreaterThanOrEqualMatcher(0); |
| 19 | + |
| 20 | + expect(matcher.match(1)).toBe(true); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should return true when the given number is equal to the expected number", () => { |
| 24 | + const matcher = new GreaterThanOrEqualMatcher(0); |
| 25 | + |
| 26 | + expect(matcher.match(0)).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + it("should return false when the given number is lower than the expected number", () => { |
| 30 | + const matcher = new GreaterThanOrEqualMatcher(0); |
| 31 | + |
| 32 | + expect(matcher.match(-1)).toBe(false); |
| 33 | + }); |
| 34 | + }); |
| 35 | + |
| 36 | + describe("#toString()", () => { |
| 37 | + it("should correctly get the string representation", () => { |
| 38 | + const expected = 0; |
| 39 | + |
| 40 | + expect(new GreaterThanOrEqualMatcher(expected).toString()).toBe(`greaterThanOrEqual(${expected})`); |
| 41 | + }); |
| 42 | + }); |
| 43 | + |
| 44 | + describe("stubbing a method", () => { |
| 45 | + let testServiceMock: TestService; |
| 46 | + let testService: TestService; |
| 47 | + |
| 48 | + beforeEach(() => { |
| 49 | + testServiceMock = imock(); |
| 50 | + testService = instance(testServiceMock); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should pass the verification when the given number is greater than the expected number", () => { |
| 54 | + const expected = 0; |
| 55 | + |
| 56 | + when(testServiceMock.testMethod(greaterThanOrEqual(expected))).thenReturn(true); |
| 57 | + |
| 58 | + const result = testService.testMethod(1); |
| 59 | + |
| 60 | + expect(result).toBe(true); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should pass the verification when the given number is equal to the expected number", () => { |
| 64 | + const expected = 0; |
| 65 | + |
| 66 | + when(testServiceMock.testMethod(greaterThanOrEqual(expected))).thenReturn(true); |
| 67 | + |
| 68 | + const result = testService.testMethod(expected); |
| 69 | + |
| 70 | + expect(result).toBe(true); |
| 71 | + }); |
| 72 | + |
| 73 | + it("should not pass the verification when the given number is lower than the expected number", () => { |
| 74 | + const expected = 0; |
| 75 | + |
| 76 | + when(testServiceMock.testMethod(greaterThanOrEqual(expected))).thenReturn(true); |
| 77 | + |
| 78 | + const result = testService.testMethod(-1); |
| 79 | + |
| 80 | + expect(result).toBeNull(); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
| 84 | + |
| 85 | +interface TestService { |
| 86 | + testMethod(date: number): boolean; |
| 87 | +} |
0 commit comments