-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a725081
commit 686ee74
Showing
6 changed files
with
454 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
globals: { | ||
'ts-jest': { | ||
useESM: true, | ||
tsconfig: { | ||
verbatimModuleSyntax: false, | ||
}, | ||
}, | ||
}, | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
globals: { | ||
"ts-jest": { | ||
useESM: true, | ||
tsconfig: { | ||
verbatimModuleSyntax: false, | ||
esModuleInterop: true, | ||
}, | ||
}, | ||
}, | ||
preset: "ts-jest", | ||
testEnvironment: "jsdom", | ||
transform: {}, | ||
}; | ||
moduleNameMapper: { | ||
"\\.(css|sass|scss)$": "identity-obj-proxy", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
packages/heartbit-react/src/components/HeartBitProvider/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import React, { useEffect } from "react"; | ||
import { render } from "@testing-library/react"; | ||
import { HeartBitContext, HeartBitProvider } from "."; | ||
import { describe, expect, jest, it } from "@jest/globals"; | ||
import { HeartBitCoreOptions } from "@fileverse/heartbit-core"; | ||
|
||
const getHeartBitByUserMock = jest.fn(); | ||
|
||
jest.mock("@fileverse/heartbit-core", () => ({ | ||
HeartBitCore: jest.fn().mockImplementation(() => { | ||
return { | ||
getHeartBitByUser: getHeartBitByUserMock, | ||
getTotalHeartBitCountByHash: jest.fn(), | ||
mintHeartBit: jest.fn(), | ||
}; | ||
}), | ||
})); | ||
|
||
describe("HeartBitProvider", () => { | ||
const coreOptions: HeartBitCoreOptions = { chain: "0xaa36a7" }; | ||
|
||
it("provides context functions", () => { | ||
const TestComponent = () => { | ||
const context = React.useContext(HeartBitContext); | ||
|
||
expect(context).not.toBeNull(); | ||
expect(context?.getTotalHeartMintsByUser).toBeDefined(); | ||
expect(context?.getTotalHeartBitByHash).toBeDefined(); | ||
expect(context?.mintHeartBit).toBeDefined(); | ||
|
||
return <div>Testing</div>; | ||
}; | ||
|
||
render( | ||
<HeartBitProvider coreOptions={coreOptions}> | ||
<TestComponent /> | ||
</HeartBitProvider> | ||
); | ||
}); | ||
|
||
it("calls getTotalHeartMintsByUser", async () => { | ||
const TestComponent = () => { | ||
const context = React.useContext(HeartBitContext); | ||
useEffect(() => { | ||
context?.getTotalHeartMintsByUser({ | ||
hash: "ipfs://test", | ||
account: "0xtest", | ||
}); | ||
}, [context]); | ||
|
||
return <div>Testing</div>; | ||
}; | ||
|
||
render( | ||
<HeartBitProvider coreOptions={coreOptions}> | ||
<TestComponent /> | ||
</HeartBitProvider> | ||
); | ||
|
||
expect(getHeartBitByUserMock).toHaveBeenCalledWith({ | ||
hash: "ipfs://test", | ||
account: "0xtest", | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.