diff --git a/typescript/option/src/helpers/bind.test.ts b/typescript/option/src/helpers/bind.test.ts index d20ca4f..d462e70 100644 --- a/typescript/option/src/helpers/bind.test.ts +++ b/typescript/option/src/helpers/bind.test.ts @@ -4,7 +4,7 @@ import { Some, None } from '../types' import { constantly } from '@thi.ng/compose' describe('The bind helper', () => { - it('should return none for any callback when given None', () => { + it('should return None for any callback when given None', () => { // act const result = bind(Some, None) diff --git a/typescript/option/src/helpers/bindAsync.test.ts b/typescript/option/src/helpers/bindAsync.test.ts new file mode 100644 index 0000000..2ec2bfe --- /dev/null +++ b/typescript/option/src/helpers/bindAsync.test.ts @@ -0,0 +1,32 @@ +import { expect } from 'chai' +import { Some, None } from '../types' +import { constantly } from '@thi.ng/compose' +import { bindAsync } from './bindAsync' + +describe('The bindAsync helper', () => { + it('should return None for any callback when given None', async () => { + // act + const result = await bindAsync(async v => Some(v), None) + + // assert + expect(result).to.equal(None) + }) + + describe('When given Some', () => { + it('should return None if the callback returns None', async () => { + // act + const result = await bindAsync(async _ => None, Some(3)) + + // assert + expect(result).to.equal(None) + }) + + it('should return Some if the callback returns Some', async () => { + // act + const result = await bindAsync(async x => Some(x + 1), Some(3)) + + // assert + expect(result).to.equal(Some(4)) + }) + }) +})