0

I am trying to test an object using proxyquire. The object is a simple JavaScript / TypeScript class with some dependencies. I am using proxyquire with sinon to override those dependencies and that's working fine. but I can't create new instance of the class to run it's methods on the test program.

I have tried to to create a static method on the class which returns new instance but the error is "Proxy.create is not a function"

// a stub of one of the dependents in 
const poolRepositoryStub = {
  insert: _.constant({}),
  '@noCallThru': true,
};

const Proxy = proxyquire('../../dist/src/components/proxy.js', {
  '../repository/pool-repository': poolRepositoryStub,
  '@noCallThru': true,
});

describe('Test ReportCheckComponent', () => {
  before(() => {   
    // this one failed say Proxy is not a constructor
    new Proxy()

    // and this one also failed on Proxy.create is not a function
    Proxy.create();
  });

  it('report-check.spec.ts: test run method using sinon stub', () => {        

    sinon
      .stub(poolRepositoryStub, 'insert')
      .returns(Promise.resolve(null))

    // ... the rest of the test code


  });
});

1 Answers1

0

My object under test is written in typescript with expert like this:

export default class MyClass { ... }

change it to:

export = MyClass;

solve the problem