descartes

0.0.9 • Public • Published

descartes NPM version Build Status Dependency Status Coverage percentage

Mock async JavaScript libraries

Install

$ npm install --save descartes

Usage

import {Jar, withArgs, withExactArgs, onThis} from 'descartes';
 
it("should behave like this", async function(){
  const jar = new Jar();
  const stub = jar.probe('stub');
  const spy = jar.sensor('spy');
  
  //start async method
  const result = myAsyncMethod(spy, stub);
 
  await spy.called();
  await spy.called(withArgs('something'));
  await spy.called(withExactArgs('something', 'else'));
  
  stub.resolvesTo('something');
  await stub.called();
  
  stub.rejects(new Error('it should handle this'));
  await stub.called(
    withArgs(13),
    onThis(window));
    
  const call = await spy.called();
  call.args[0].should.equal('something');
  call.args[1].should.be.a('Function');
  call.args[1](null, 'result');
  
  (await result).should.equal('expected value');
});
 

License

MIT © Marius Gundersen

Readme

Keywords

Package Sidebar

Install

npm i descartes

Weekly Downloads

8

Version

0.0.9

License

MIT

Last publish

Collaborators

  • mariusgundersen