import { assertFork , jestAssertNever , jestAssertUntypedNeverCalled } from '../../test/jest-helper' ; import { Task } from './index' ; describe ( 'Task' , ( ) => { describe ( 'fork' , ( ) => { it ( 'should be lazy (dont call if not forked)' , cb => { const task = new Task ( resolve => { expect ( true ) . toBe ( false ) ; } ) ; setTimeout ( cb , 20 ) ; } ) ; it ( 'should be lazy (called when forked)' , cb => { const task = new Task ( resolve => { expect ( true ) . toBe ( true ) ; cb ( ) ; } ) ; task . fork ( x => x , x => x ) ; } ) ; it ( 'Should be asynchronous' , cb => { const task = new Task < string , never > ( resolve => setTimeout ( _ => resolve ( 'wii' ) , 10 ) ) ; task . fork ( jestAssertNever ( cb ) , assertFork ( cb , x => expect ( x ) . toBe ( 'wii' ) ) ) ; } ) ; it ( 'Should call success handler on success' , cb => { const task = Task . resolve ( 0 ) ; task . fork ( jestAssertNever ( cb ) , assertFork ( cb , x => expect ( x ) . toBe ( 0 ) ) ) ; } ) ; it ( 'Should call error handler on rejection' , cb => { const task = Task . reject ( 'buu' ) ; task . fork ( assertFork ( cb , x => expect ( x ) . toBe ( 'buu' ) ) , jestAssertNever ( cb ) ) ; } ) ; } ) ; } ) ;