diff --git a/typescript/option/src/helpers/withDefault.test.ts b/typescript/option/src/helpers/withDefault.test.ts new file mode 100644 index 0000000..a661b2a --- /dev/null +++ b/typescript/option/src/helpers/withDefault.test.ts @@ -0,0 +1,22 @@ +import { expect } from 'chai' +import { withDefault } from './withDefault' +import { x } from '../../test/constants' +import { None, Some } from '../types' + +describe('The withDefault helper', () => { + it('should return the default when given None', () => { + // act + const result = withDefault(x, None) + + // assert + expect(result).to.equal(x) + }) + + it('should return x when given Some(x)', () => { + // act + const result = withDefault(0, Some(1)) + + // assert + expect(result).to.equal(1) + }) +})