import { assertFork , jestAssertNever } from '../../test/jest-helper' ; import { map } from '../operators' ; import { Task } from '../task' ; import { UnknownError } from '../task/unknown-error' ; describe ( 'Task' , ( ) => { describe ( 'map' , ( ) => { it ( 'Should handle transformation functions (dot-chaining)' , ( cb ) => { const task = Task . resolve ( 0 ) ; const result = task . map ( n => '' + n ) ; result . fork ( jestAssertNever ( cb ) , assertFork ( cb , x => expect ( x ) . toBe ( '0' ) ) ) ; } ) ; it ( 'Should handle transformation functions (pipe)' , ( cb ) => { const task = Task . resolve ( 0 ) ; const result = task . pipe ( map ( n => '' + n ) ) ; result . fork ( jestAssertNever ( cb ) , assertFork ( cb , x => expect ( x ) . toBe ( '0' ) ) ) ; } ) ; it ( 'Should handle functions that throw' , ( cb ) => { const resolved = Task . resolve ( 0 ) ; const result = resolved . map ( n => { throw new Error ( 'buu' ) ; } ) ; result . fork ( assertFork ( cb , x => expect ( x instanceof UnknownError ) . toBe ( true ) ) , jestAssertNever ( cb ) ) ; } ) ; it ( 'Should propagate error' , ( cb ) => { const rejected = Task . reject ( 'buu' ) ; const result = rejected . map ( jestAssertNever ( cb ) ) ; result . fork ( assertFork ( cb , x => expect ( x ) . toBe ( 'buu' ) ) , jestAssertNever ( cb ) ) ; } ) ; } ) ; } ) ;