|
1 |
| -import { maybe } from './public_api' |
| 1 | +import { maybe, none } from './public_api' |
2 | 2 | import { Maybe } from './maybe'
|
3 | 3 |
|
4 | 4 | describe('Maybe', () => {
|
@@ -616,4 +616,64 @@ describe('Maybe', () => {
|
616 | 616 | expect(sut.unwrapFail()).toEqual(new Error('oops'))
|
617 | 617 | })
|
618 | 618 | })
|
| 619 | + |
| 620 | + describe('tapThruSome', () => { |
| 621 | + it('should tapThruSome', () => { |
| 622 | + // eslint-disable-next-line prefer-const |
| 623 | + let variable: undefined | number = undefined |
| 624 | + const hasSome = maybe(1) |
| 625 | + const sut = hasSome.tapThruSome((v) => { |
| 626 | + variable = v + 9 |
| 627 | + }) |
| 628 | + expect(sut.isSome()).toBeTruthy() |
| 629 | + expect(sut.valueOrThrowErr()).toEqual(1) |
| 630 | + expect(variable).toEqual(10) |
| 631 | + expect(sut).toBeInstanceOf(Maybe) |
| 632 | + }) |
| 633 | + }) |
| 634 | + |
| 635 | + describe('tapThruNone', () => { |
| 636 | + it('should tapThruNone', () => { |
| 637 | + // eslint-disable-next-line prefer-const |
| 638 | + let variable: undefined | string = undefined |
| 639 | + const hasSome = none<string>() |
| 640 | + const sut = hasSome.tapThruNone(() => { |
| 641 | + variable = 'whatever' |
| 642 | + }) |
| 643 | + expect(sut.isNone()).toBeTruthy() |
| 644 | + expect(sut.valueOrUndefined()).toBeUndefined() |
| 645 | + expect(variable).toEqual('whatever') |
| 646 | + expect(sut).toBeInstanceOf(Maybe) |
| 647 | + }) |
| 648 | + }) |
| 649 | + |
| 650 | + describe('tapThru', () => { |
| 651 | + it('should tap on some ', () => { |
| 652 | + // eslint-disable-next-line prefer-const |
| 653 | + let variable: undefined | string = undefined |
| 654 | + const hasSome = maybe<string>('hi there') |
| 655 | + const sut = hasSome.tapThru({ |
| 656 | + none: () => {}, |
| 657 | + some: (v) => { variable = v + ' joe'} |
| 658 | + }) |
| 659 | + expect(sut.isSome()).toBeTruthy() |
| 660 | + expect(sut.valueOrThrowErr()).toBeTruthy() |
| 661 | + expect(variable).toEqual('hi there joe') |
| 662 | + expect(sut).toBeInstanceOf(Maybe) |
| 663 | + }) |
| 664 | + |
| 665 | + it('should tap on none ', () => { |
| 666 | + // eslint-disable-next-line prefer-const |
| 667 | + let variable: undefined | string = undefined |
| 668 | + const hasSome = none<string>() |
| 669 | + const sut = hasSome.tapThru({ |
| 670 | + none: () => { variable = 'sorry joe' }, |
| 671 | + some: (v) => { variable = v + ' joe' } |
| 672 | + }) |
| 673 | + expect(sut.isNone()).toBeTruthy() |
| 674 | + expect(sut.valueOrUndefined()).toBeUndefined() |
| 675 | + expect(variable).toEqual('sorry joe') |
| 676 | + expect(sut).toBeInstanceOf(Maybe) |
| 677 | + }) |
| 678 | + }) |
619 | 679 | })
|
0 commit comments