0

I would like to be able to stub the encode function inside of the jwt-simple library.

Something like this:

import { encode } from 'jwt-simple';

sinon.stub(encode).returns('your encoded string');

Is this possible? I have been trying to find solutions and workaround but have not been successful.

I'm open to ideas. Thanks

ez33
  • 531
  • 4
  • 4
  • For a test? It's not clear in what context you're asking--if you want to stub the only function you're importing, why import it? – Dave Newton Feb 27 '19 at 18:04

1 Answers1

0

The stubbing in your case be done simply by importing jwt-simple as reference.

import * as jwtSimple from 'jwt-simple'; // as reference

sinon.stub(jwtSimple, 'encode').returns('your encoded string');

Hope it helps

deerawan
  • 8,002
  • 5
  • 42
  • 51