Skip to content

Commit

Permalink
Use expect.anything() in tests to also tests all arguments received
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayc0 committed Jul 30, 2023
1 parent 3ed2391 commit 1e5d419
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/manatea/__tests__/manatea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe('Manatea', () => {
it('should be listenable', async () => {
const cup = orderCup<number>(1);
const fn = jest.fn();
cup.on(tea => fn(tea));
cup.on(fn);
await cup(2);
expect(fn).toHaveBeenCalledWith(2);
expect(fn).toHaveBeenCalledWith(2, expect.anything());
await cup(2);
expect(fn).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -78,16 +78,16 @@ describe('Manatea', () => {
},
);
const fn = jest.fn();
cup.on(tea => fn(tea));
cup.on(fn);
expect(cup()).toBe(0);

await cup('1');
expect(cup()).toBe(1);
expect(fn).toHaveBeenCalledWith(1);
expect(fn).toHaveBeenCalledWith(1, expect.anything());

await cup('2');
expect(cup()).toBe(3);
expect(fn).toHaveBeenCalledWith(3);
expect(fn).toHaveBeenCalledWith(3, expect.anything());
});

describe('derived cups', () => {
Expand All @@ -112,15 +112,15 @@ describe('Manatea', () => {
});

const fn = jest.fn();
derivedCup.on(tea => fn(tea));
derivedCup.on(fn);

await cup2(5);
await cup1(10);

expect(derivedCup()).toBe(15);
expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledWith(6);
expect(fn).toHaveBeenCalledWith(15);
expect(fn).toHaveBeenCalledWith(6, expect.anything());
expect(fn).toHaveBeenCalledWith(15, expect.anything());
});

it('should be handle to re-use the same cup multiple times', async () => {
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('Manatea', () => {
);

const fn = jest.fn();
derivedCup.on(tea => fn(tea));
derivedCup.on(fn);

expect(derivedCup()).toBe(12);

Expand All @@ -160,8 +160,8 @@ describe('Manatea', () => {
expect(derivedCup()).toBe(105);

expect(fn).toHaveBeenCalledTimes(2);
expect(fn).toHaveBeenCalledWith(15);
expect(fn).toHaveBeenCalledWith(105);
expect(fn).toHaveBeenCalledWith(15, expect.anything());
expect(fn).toHaveBeenCalledWith(105, expect.anything());
});

it('works with setters', async () => {
Expand Down

0 comments on commit 1e5d419

Please sign in to comment.