Skip to content

Instantly share code, notes, and snippets.

@bennycode
Last active September 1, 2019 22:45
Show Gist options
  • Select an option

  • Save bennycode/83c59d04c2c82febdbda048c972470a9 to your computer and use it in GitHub Desktop.

Select an option

Save bennycode/83c59d04c2c82febdbda048c972470a9 to your computer and use it in GitHub Desktop.
Jasmine Samples
import Spy = jasmine.Spy;
spyOn(exchange['client'], 'candles').and.callFake(() => {
const candlesSpy = (exchange['client'].candles as Spy);
switch (candlesSpy.calls.count()) {
case 1:
return require('../test/fixtures/binance/candles/BTC-USDT-1m-500-1561500000000.json');
case 2:
return require('../test/fixtures/binance/candles/BTC-USDT-1m-500-1561530000000.json');
default:
return require('../test/fixtures/binance/candles/BTC-USDT-1m-500-1561560000000.json');
}
});
// Check arguments that has been used to call a spy
const eventSpy = jasmine.createSpy('onCandle');
expect(eventSpy).toHaveBeenCalledTimes(1);
const emittedCandle: Object = eventSpy.calls.mostRecent().args.pop();
expect(emittedCandle.a).toEqual('a');
expect(emittedCandle.b).toEqual('b');
// Alternative
const eventSpy = jasmine.createSpy('onCandle');
expect(orderSpy).toHaveBeenCalledWith({
a: 'a',
b: 'b',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment