Skip to content

Commit

Permalink
refactor(microtask): split test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nattallius committed Jan 26, 2024
1 parent f421e88 commit c3af68b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/modules/esl-utils/async/test/microtask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ describe('sync/microtask', () => {
await Promise.resolve();
expect(fn).toBeCalledTimes(1);
});
test('Decorated as microtask callback receives a correct list of call arguments', async () => {
test('Decorated as microtask callback receives a list of call arguments', async () => {
const fn = jest.fn();
const decorated = microtask(fn);
const params1 = [Symbol('Arg 1'), Symbol('Arg 2'), Symbol('Arg 3')];
const params = [Symbol('Arg 1'), Symbol('Arg 2'), Symbol('Arg 3')];

for (const param of params) decorated(param);
await Promise.resolve();
expect(fn).toBeCalledWith(expect.arrayContaining(params));
});
test('Decorated as microtask callback refreshes after decorated method call (leak protected)', async () => {
const fn = jest.fn();
const decorated = microtask(fn);
const params1 = [Symbol('Arg 1'), Symbol('Arg 2')];
for (const param of params1) decorated(param);
await Promise.resolve();
expect(fn).toBeCalledWith(params1);

const params2 = [Symbol('Arg 4'), Symbol('Arg 5')];
const params2 = [Symbol('Arg 3'), Symbol('Arg 4')];
for (const param of params2) decorated(param);
await Promise.resolve();
expect(fn).lastCalledWith(params2);
Expand Down

0 comments on commit c3af68b

Please sign in to comment.