diff --git a/typescript/option/src/helpers/filter.test.ts b/typescript/option/src/helpers/filter.test.ts new file mode 100644 index 0000000..5a38f88 --- /dev/null +++ b/typescript/option/src/helpers/filter.test.ts @@ -0,0 +1,47 @@ +import { expect } from 'chai' +import { constantly } from '@thi.ng/compose' +import { filter } from './filter' +import { None, Some } from '../types' +import { someX } from '../../test/constants' + +describe('The filter helper', () => { + describe('When the predicate returns true', () => { + const predicate = constantly(true) + + it('should return None when given None', () => { + // act + const result = filter(predicate, None) + + // assert + expect(result).to.equal(None) + }) + + it('should return Some(x) when given Some(x)', () => { + // act + const result = filter(predicate, someX) + + // assert + expect(result).to.equal(someX) + }) + }) + + describe('When the predicate returns false', () => { + const predicate = constantly(false) + + it('should return None when given Some', () => { + // act + const result = filter(predicate, someX) + + // assert + expect(result).to.equal(None) + }) + + it('should return None when given None', () => { + // act + const result = filter(predicate, None) + + // assert + expect(result).to.equal(None) + }) + }) +}) diff --git a/typescript/option/test/constants.ts b/typescript/option/test/constants.ts index 329bc93..1ebdc08 100644 --- a/typescript/option/test/constants.ts +++ b/typescript/option/test/constants.ts @@ -1,2 +1,7 @@ +import { Some } from '../src' + // general value to pass around export const x = Symbol('x') + +// same as x but for some +export const someX = Some(x) diff --git a/typescript/option/tsconfig.json b/typescript/option/tsconfig.json index 46c5041..6e4fb37 100644 --- a/typescript/option/tsconfig.json +++ b/typescript/option/tsconfig.json @@ -8,5 +8,6 @@ "downlevelIteration": true, "target": "es6" }, - "include": ["src", "sandbox", "test"] + "include": ["src", "sandbox", "test"], + "exclude": ["dist"] }