Skip to content

Commit

Permalink
Merge pull request #34 from Ayc0/Ayc0/tests-anything
Browse files Browse the repository at this point in the history
tests: use expect.anything()
  • Loading branch information
Ayc0 authored Jul 30, 2023
2 parents 3ed2391 + 6191dee commit 4b02c25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 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
6 changes: 3 additions & 3 deletions packages/react-manatea/__tests__/useInfuser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 4b02c25

Please sign in to comment.