Skip to content

Commit

Permalink
improve handling of empty optionals
Browse files Browse the repository at this point in the history
  • Loading branch information
manusant committed May 2, 2024
1 parent 3b02796 commit db5f37d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions test/optional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('Optional Class Tests', () => {
});

it('should throw an error for map on an empty Optional', () => {
const optional = Optional.empty();
const optional = Optional.empty<number>();
expect( optional.flatMap((x) => Optional.of( 2*(x||1))).isEmpty()).toBe(true);
});
});
Expand All @@ -176,7 +176,7 @@ describe('Optional Class Tests', () => {
});

it('should not execute the consumer for an empty Optional', () => {
const optional = Optional.empty();
const optional = Optional.empty<number>();
let result = 0;
optional.ifPresent((x) => (result = x!));
expect(result).toBe(0);
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('Optional Class Tests', () => {
});

it('should throw an error for map on an empty Optional', () => {
const optional = Optional.empty();
const optional = Optional.empty<number>();
expect( optional.map((x) => (x || 1) * 2).isEmpty()).toBe(true);
});
});
Expand All @@ -285,7 +285,7 @@ describe('Optional Class Tests', () => {
});

it('should not execute the consumer for an empty Optional', () => {
const optional = Optional.empty();
const optional = Optional.empty<number>();
let result = 0;
optional.ifPresent((x) => (result = x!));
expect(result).toBe(0);
Expand Down

0 comments on commit db5f37d

Please sign in to comment.