From 2b681bfa7f86ecb03e175f1002cabd87e9500d13 Mon Sep 17 00:00:00 2001 From: Matei Adriel Date: Mon, 23 Dec 2019 16:11:20 +0200 Subject: [PATCH] typescript(option): test: added tests for exists Signed-off-by: prescientmoon --- typescript/option/src/helpers/exists.test.ts | 33 ++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 typescript/option/src/helpers/exists.test.ts diff --git a/typescript/option/src/helpers/exists.test.ts b/typescript/option/src/helpers/exists.test.ts new file mode 100644 index 0000000..32f8494 --- /dev/null +++ b/typescript/option/src/helpers/exists.test.ts @@ -0,0 +1,33 @@ +import { expect } from 'chai' +import { exists } from './exists' +import { constantly } from '@thi.ng/compose' +import { None, Some } from '../types' +import { x } from '../../test/constants' + +describe('The exists helper', () => { + it('should return false when given None', () => { + // act + const result = exists(constantly(true), None) + + // assert + expect(result).to.equal(false) + }) + + describe('When given Some', () => { + it('should return true if the callback returns true', () => { + // act + const result = exists(constantly(true), Some(x)) + + // assert + expect(result).to.equal(true) + }) + + it('should return false if the callback returns false', () => { + // act + const result = exists(constantly(false), Some(x)) + + // assert + expect(result).to.equal(false) + }) + }) +})