1

I have a class like the one shown here:

import {otherStuff} from 'somewhere'

const promiseFtp = require('promise-ftp');

export class processor(){
  ftp: any;

  public async connect(){
    ftp = new promiseFtp();
    await ftp.connect(myConnectionObject);
    this.ftp = ftp;
  }
}

My problem is that I have no way to mock promiseFtp. I cant find any documentation in Jasmine that supports this sort of testing. I would let it just call the connect function, but I dont want it to actually connect to any ftp site.

I might be able to use something like proxyquire, but my boss is against it since we moved to typescript, and that was supposed to get rid of proxyquire. I cannot use proxyquire Typescript should have a way around this somehow.

I even tried to my my own module that exports promiseFtp, then mocks that module, but I just cant do it. How do you mock a class so that it wont get called.

Samuel Thompson
  • 2,429
  • 4
  • 24
  • 34
  • Possible duplicate of [How to unit test a node.js module that requires other modules](https://stackoverflow.com/questions/5747035/how-to-unit-test-a-node-js-module-that-requires-other-modules) – Daniel A. White Nov 22 '17 at 01:52
  • well it is different only because of typescript. with typescript proxyquire is supposed to be not necessary any more. – Samuel Thompson Nov 22 '17 at 01:55
  • There's a [sinon](http://sinonjs.org/) based [answer on that page as well](https://stackoverflow.com/a/16308099/1318694) – Matt Nov 22 '17 at 05:24
  • I am using jasmine, and that is sinon. also it does not solve the problem. The problem is that I am trying to stub a class inside a module that is in a different file. – Samuel Thompson Nov 22 '17 at 17:21

0 Answers0