const mockPlaySoundFile = jest . fn ( ) ; jest . mock ( './SoundPlayer' , ( ) => { return { SoundPlayer : jest . fn ( ) . mockImplementation ( ( ) => { return { playSoundFile : mockPlaySoundFile } ; } ) } ; } ) ; import { SoundPlayerConsumer } from './SoundPlayerConsumer' ; import { SoundPlayer } from './SoundPlayer' ; beforeEach ( ( ) => { mocked ( SoundPlayer ) . mockClear ( ) ; mockPlaySoundFile . mockClear ( ) ; } ) ; it ( 'The consumer should be able to call new() on SoundPlayer' , ( ) => { const soundPlayerConsumer = new SoundPlayerConsumer ( ) ; expect ( soundPlayerConsumer ) . toBeTruthy ( ) ; } ) ; it ( 'We can check if the consumer called the class constructor' , ( ) => { new SoundPlayerConsumer ( ) ; expect ( SoundPlayer ) . toHaveBeenCalledTimes ( 1 ) ; } ) ; it ( 'We can check if the consumer called a method on the class instance' , ( ) => { const soundPlayerConsumer = new SoundPlayerConsumer ( ) ; const coolSoundFileName = 'song.mp3' ; soundPlayerConsumer . playSomethingCool ( ) ; expect ( mockPlaySoundFile . mock . calls [ 0 ] [ 0 ] ) . toEqual ( coolSoundFileName ) ; } ) ;