Last active
September 1, 2019 22:45
-
-
Save bennycode/83c59d04c2c82febdbda048c972470a9 to your computer and use it in GitHub Desktop.
Jasmine Samples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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