import { assertFork , jestAssertNever , jestAssertUntypedNeverCalled } from '../../test/jest-helper' ; import { Task } from './index' ; describe ( 'Task' , ( ) => { describe ( 'fromPromise' , ( ) => { it ( 'Should work with resolved promises' , ( cb ) => { const resolved = Task . fromPromise ( Promise . resolve ( 0 ) ) ; resolved . fork ( jestAssertNever ( cb ) , assertFork ( cb , x => expect ( x ) . toBe ( 0 ) ) ) ; } ) ; it ( 'Should work with rejected promises' , ( cb ) => { const resolved = Task . fromPromise ( Promise . reject ( 'buu' ) ) ; resolved . fork ( assertFork ( cb , x => expect ( x ) . toBe ( 'buu' ) ) , jestAssertNever ( cb ) ) ; } ) ; it ( 'Should mantain any error when changed' , ( cb ) => { const task = Task . fromPromise ( Promise . reject ( 'buu' ) ) ; const result = task . chain ( _ => Task . resolve ( 0 ) ) ; result . fork ( assertFork ( cb , x => expect ( x ) . toBe ( 'buu' ) ) , jestAssertUntypedNeverCalled ( cb ) ) ; } ) ; it ( 'Should be able to set rejected type' , ( cb ) => { const resolved = Task . fromPromise < never , string > ( Promise . reject ( 'buu' ) ) ; resolved . fork ( assertFork ( cb , x => expect ( x ) . toBe ( 'buu' ) ) , jestAssertNever ( cb ) ) ; } ) ; } ) ; } ) ;