From 1e5d419d13d35f0f4547b28f96cd5b2d9d8c2bd7 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Sun, 30 Jul 2023 23:49:04 +0200 Subject: [PATCH 1/2] Use expect.anything() in tests to also tests all arguments received --- packages/manatea/__tests__/manatea.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/manatea/__tests__/manatea.ts b/packages/manatea/__tests__/manatea.ts index 73e81e0..372a4b9 100644 --- a/packages/manatea/__tests__/manatea.ts +++ b/packages/manatea/__tests__/manatea.ts @@ -16,9 +16,9 @@ describe('Manatea', () => { it('should be listenable', async () => { const cup = orderCup(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); }); @@ -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', () => { @@ -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 () => { @@ -151,7 +151,7 @@ describe('Manatea', () => { ); const fn = jest.fn(); - derivedCup.on(tea => fn(tea)); + derivedCup.on(fn); expect(derivedCup()).toBe(12); @@ -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 () => { From 6191dee9953b4d9d9c69e9d08f0245bcf0d03cc9 Mon Sep 17 00:00:00 2001 From: Ayc0 Date: Sun, 30 Jul 2023 23:51:35 +0200 Subject: [PATCH 2/2] Use expect.anything() in tests to also tests all arguments received in useInfuser --- packages/react-manatea/__tests__/useInfuser.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-manatea/__tests__/useInfuser.ts b/packages/react-manatea/__tests__/useInfuser.ts index c567c05..b0065dc 100644 --- a/packages/react-manatea/__tests__/useInfuser.ts +++ b/packages/react-manatea/__tests__/useInfuser.ts @@ -63,19 +63,19 @@ describe('useInfuser', () => { expect(result.current[0]).toBe(0); const fn = jest.fn(); - cup.on(tea => fn(tea)); + cup.on(fn); await act(async () => { await result.current[1]('1'); }); expect(cup()).toBe(1); - expect(fn).toHaveBeenCalledWith(1); + expect(fn).toHaveBeenCalledWith(1, expect.anything()); await act(async () => { await result.current[1]('2'); }); expect(cup()).toBe(3); - expect(fn).toHaveBeenCalledWith(3); + expect(fn).toHaveBeenCalledWith(3, expect.anything()); }); it('should work with derived cups', async () => {