Mocking node dependency for Typescript with Mocha / Sinon

I have a class which controls an audio receiver using an external library marantz-avr:

let AVReceiver = require('marantz-avr');

class MarantzPlugin {


    constructor(pluginConfiguration) {
        const receiver = new AVReceiver(pluginConfiguration.settings.ip);
        this.hardwareInstance = receiver;

    turnPowerOn() {
        this.hardwareInstance.setPowerState('on').then(res => res, error => console.error(error));


export default MarantzPlugin;

I want to unit test this class. In order to do so I have to mock the marantz-avr library since this library only works when an actual receiver is found on the provided ip address.

In the test below I mock the marantz-avr, however the MarantzPlugin still uses the original AVReceiver instead of the mocked one.

import { suite, test, slow, timeout } from 'mocha-typescript';
import * as mocha from 'mocha';
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as should from 'should';

import MarantzPlugin from './';
let AVReceiver = require('marantz-avr');

class MarantzPluginTest {

    public create() {

        before(() => {
            sinon.stub(AVReceiver.prototype, 'AVReceiver').callsFake(() => {

                return {
                    setPowerState: () => {
                        return true;

        let marantz = new MarantzPlugin({
            id: 'MARANTZ',
            settings: {
                ip: '',




I've looked into but when implemented it gave me Error: Cannot find module 'marantz-avr'

Does anyone see what I am missing here, or perhaps have a better way to unit test these kind of classes?