UNPKG

@qiniu/miku-delivery-mp-ks

Version:

Kuaishou Mini Program SDK for Miku Delivery

47 lines (46 loc) 2.27 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { delayValue } from '../test'; import { collapseCalls } from './async'; describe('collapseCalls', () => { it('should work well', () => __awaiter(void 0, void 0, void 0, function* () { const _run = jest.fn((input) => __awaiter(void 0, void 0, void 0, function* () { return delayValue(input, 100); })); const run = collapseCalls(_run, i => i); const o1Promise = run('123'); const [o2, o3, o4] = yield Promise.all(['123', '456', '123'].map(i => run(i))); expect(yield o1Promise).toBe('123'); expect(o2).toBe('123'); expect(o3).toBe('456'); expect(o4).toBe('123'); expect(_run).toBeCalledTimes(2); expect(_run).toBeCalledWith('123'); expect(_run).toBeCalledWith('456'); yield run('123'); expect(_run).toBeCalledTimes(3); })); it('should work well with getKey', () => __awaiter(void 0, void 0, void 0, function* () { const _run = jest.fn((input) => __awaiter(void 0, void 0, void 0, function* () { return delayValue(input, 100); })); const run = collapseCalls(_run, () => '123'); const [o1, o2, o3] = yield Promise.all(['123', '456', '123'].map(i => run(i))); expect(o1).toBe('123'); expect(o2).toBe('123'); expect(o3).toBe('123'); expect(_run).toBeCalledTimes(1); expect(_run).toBeCalledWith('123'); const o4 = yield run('456'); expect(o4).toBe('456'); expect(_run).toBeCalledTimes(2); expect(_run).toBeCalledWith('456'); })); });