1 import unary from './unary';
3 describe('unary()', () => {
4 it('should handle functions with no arguments', () => {
5 const myFunction = () => {
9 const unaryFunction = unary(myFunction);
11 expect(unaryFunction('I still require an argument')).toEqual('myFunction');
14 it('should handle functions with a single argument', () => {
15 const myFunction = (arg: string) => {
19 const unaryFunction = unary(myFunction);
21 expect(unaryFunction('Argument')).toEqual('Argument');
24 it('should ensure only one argument is passed', () => {
25 const myFunction = (name: string, index?: number) => {
26 if (index === undefined) {
29 return `Ola ${name} - ${index}`;
31 const names = ['Joao', 'Felix', 'Tareixa'];
32 expect(names.map(myFunction)).toEqual(['Ola Joao - 0', 'Ola Felix - 1', 'Ola Tareixa - 2']);
33 expect(names.map(unary(myFunction))).toEqual(['Ola Joao', 'Ola Felix', 'Ola Tareixa']);