import * as assert from 'assert' ; import * as T from 'fp-ts/lib/Task' ; import * as C from 'fp-ts/lib/Console' ; import * as L from '../src/Task' ; describe ( 'TaskLogger' , ( ) => { let ledger ; let consolelog ; const asyncLog = ( s ) => T . fromIO ( C . log ( s ) ) ; beforeEach ( ( ) => { ledger = [ ] ; consolelog = console . log ; console . log = ( message ) => ledger . push ( message ) ; } ) ; afterEach ( ( ) => { console . log = consolelog ; } ) ; it ( 'contramap' , ( ) => { const logger = L . loggerTask . contramap ( asyncLog , ( s ) => s . length ) ; logger ( 'a' ) ( ) ; assert . deepEqual ( ledger , [ 1 ] ) ; } ) ; it ( 'getSemigroup' , ( ) => { const S = L . getMonoid < string > ( ) ; const logger = S . concat ( asyncLog , asyncLog ) ; logger ( 'a' ) ( ) ; assert . deepEqual ( ledger , [ 'a' , 'a' ] ) ; } ) ; it ( 'getMonoid' , ( ) => { const M = L . getMonoid < string > ( ) ; const logger = M . concat ( asyncLog , M . empty ) ; logger ( 'a' ) ( ) ; assert . deepEqual ( ledger , [ 'a' ] ) ; } ) ; it ( 'filter' , ( ) => { const logger = L . filter ( asyncLog , ( a ) => a . length > 2 ) ; logger ( 'a' ) ( ) ; logger ( 'aaa' ) ( ) ; assert . deepEqual ( ledger , [ 'aaa' ] ) ; } ) ; } ) ;