asynctest

Why is jest.useFakeTimers not working with RxJs Observable delay

不羁的心 提交于 2019-12-18 07:03:04
问题 I'm wondering why jest.useFakeTimers is working with setTimeout but not with the delay operator of RxJs: jest.useFakeTimers(); import {Observable} from 'rxjs/Observable'; import 'rxjs'; describe('timers', () => { it('should resolve setTimeout synchronously', () => { const spy = jest.fn(); setTimeout(spy, 20); expect(spy).not.toHaveBeenCalled(); jest.runTimersToTime(20); expect(spy).toHaveBeenCalledTimes(1); }); it('should resolve setInterval synchronously', () => { const spy = jest.fn();

How to mock aiohttp.client.ClientSession.get async context manager

余生颓废 提交于 2019-12-04 11:00:34
问题 I have some troubles with mocking aiohttp.client.ClientSession.get context manager. I found some articles and here is one example that seems was working: article 1 So my code that I want to test: async_app.py import random from aiohttp.client import ClientSession async def get_random_photo_url(): while True: async with ClientSession() as session: async with session.get('random.photos') as resp: json = await resp.json() photos = json['photos'] if not photos: continue return random.choice