jest . mock ( './SoundPlayer' ) ; import { SoundPlayer } from './SoundPlayer' ; import { mockPlaySoundFile } from './__mocks__/SoundPlayer' ; import { SoundPlayerConsumer } from './SoundPlayerConsumer' ; beforeEach ( ( ) => { mocked ( SoundPlayer ) . mockClear ( ) ; mockPlaySoundFile . mockClear ( ) ; } ) ; 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 ) . toHaveBeenCalledWith ( coolSoundFileName ) ; } ) ; import { SoundPlayer as MockSoundPlayer } from './__mocks__/SoundPlayer' ; it ( 'Importing ./__mocks__/SoundPlayer returns the same object as importing ./SoundPlayer' , ( ) => { expect ( SoundPlayer ) . toBe ( MockSoundPlayer ) ; } ) ;