Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

#136 test and docs for useAreSigerEqual #181

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/hooks/useAreSignerEqual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const queryKey = { namespace: keyNamespace.signer, key: 'useAreSignerEqual' } as
*
* @category Hooks
*
* @param signer1
* @param signer1 Object for first signer to compare
* @param signer2 Object for second signer to compare
* @param options Options for how often and when to update
* @returns
*/
export const useAreSignerEqual = (
Expand Down
68 changes: 68 additions & 0 deletions test/useAreSignerEqual.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { expect } from 'chai';

import { useAreSignerEqual } from '~~';
import { defaultBlockWaitOptions } from '~~/helpers/test-utils/constants';
import { getHardhatSigner, hookTestWrapper } from '~~/helpers/test-utils/wrapper';
import { TEthersSigner } from '~~/models';

type InputType = {
signer1: TEthersSigner | undefined;
signer2: TEthersSigner | undefined;
};

describe('useAreSignerEqual', () => {
it('When signers are the same; then returns true', async () => {
// ::Given::
const harness = await hookTestWrapper(({ signer1, signer2 }: InputType) => useAreSignerEqual(signer1, signer2));
const signer1 = await getHardhatSigner(harness.mockProvider, 1);

// ::When::
harness.rerender({ signer1, signer2: signer1 });
await harness.waitForValueToChange(() => harness.result.current[0], defaultBlockWaitOptions);

// ::Then::
expect(harness.result.current[0]).be.equal(true);
});

it('When signers have different address; then returns false', async () => {
// ::Given::
const harness = await hookTestWrapper(({ signer1, signer2 }: InputType) => useAreSignerEqual(signer1, signer2));
const signer1 = await getHardhatSigner(harness.mockProvider, 1);
const signer2 = await getHardhatSigner(harness.mockProvider, 2);

// ::When::
harness.rerender({ signer1, signer2 });
await harness.waitForValueToChange(() => harness.result.current[0], defaultBlockWaitOptions);

// ::Then::
expect(harness.result.current[0]).be.equal(false);
});

it('When signer1 is undefined (has no network); then returns undefined', async () => {
// ::Given::
const harness = await hookTestWrapper(({ signer1, signer2 }: InputType) => useAreSignerEqual(signer1, signer2));
const signer1 = undefined;
const signer2 = await getHardhatSigner(harness.mockProvider, 2);

// ::When::
harness.rerender({ signer1, signer2 });
await harness.waitFor(() => harness.result.current[0], defaultBlockWaitOptions);

// ::Then::
expect(harness.result.current[0]).be.equal(undefined);
});

it('When signer2 is undefined; then returns false', async () => {
// ::Given::
const harness = await hookTestWrapper(({ signer1, signer2 }: InputType) => useAreSignerEqual(signer1, signer2));
const signer1 = await getHardhatSigner(harness.mockProvider, 0);
const signer2 = undefined;

// ::When::
harness.rerender({ signer1, signer2 });
await harness.waitForValueToChange(() => harness.result.current[0], defaultBlockWaitOptions);

// ::Then::
expect(harness.result.current[0]).be.equal(false);
});
});