From 1a443ee3492a5fd8db4e8e7e9623df78b5215ad7 Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Mon, 23 Dec 2019 16:01:51 +0200 Subject: [PATCH] typescript(option): test: added tests for bindAsync Signed-off-by: prescientmoon --- typescript/option/src/helpers/bind.test.ts | 2 +- .../option/src/helpers/bindAsync.test.ts | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 typescript/option/src/helpers/bindAsync.test.ts 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)) + }) + }) +})