feat: jest testing setup, example tests (#181)

This commit is contained in:
Yusuf Seyrek
2023-05-08 16:47:19 +02:00
committed by GitHub
parent 93ab5efe06
commit ae1f8d481b
11 changed files with 1929 additions and 36 deletions
@@ -0,0 +1,29 @@
import { render, screen } from '@testing-library/react'
import * as useParams from 'utils/route'
import AccountDetails from 'components/Account/AccountDetails'
jest.mock('utils/route')
const mockedUseParams = useParams.default as jest.Mock
describe('<AccountDetails />', () => {
afterAll(() => {
mockedUseParams.mockRestore()
})
it('renders account details WHEN accountId specified in the params', () => {
mockedUseParams.mockReturnValue({ accountId: 1 })
render(<AccountDetails />)
const container = screen.queryByTestId('account-details')
expect(container).toBeInTheDocument()
})
it('does not render WHEN accountId is NOT specified in the params', () => {
mockedUseParams.mockReturnValue({ accountId: null })
render(<AccountDetails />)
const container = screen.queryByTestId('account-details')
expect(container).not.toBeInTheDocument()
})
})
+33
View File
@@ -0,0 +1,33 @@
import { getVaultMetaData } from 'utils/vaults'
import * as constants from 'constants/env'
jest.mock('constants/env', () => ({
__esModule: true,
get IS_TESTNET() {
return true
},
}))
describe('getVaultMetaData()', () => {
afterAll(() => {
jest.restoreAllMocks()
})
it('returns the MAINNET vault of given address WHEN environment configured to mainnet', () => {
jest.spyOn(constants, 'IS_TESTNET', 'get').mockReturnValue(false)
const testAddress = 'osmo1g3kmqpp8608szfp0pdag3r6z85npph7wmccat8lgl3mp407kv73qlj7qwp'
const testVaultName = 'OSMO-ATOM'
expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName)
})
it('returns the TESTNET vault of given address WHEN environment configured to testnet', () => {
jest.spyOn(constants, 'IS_TESTNET', 'get').mockReturnValue(true)
const testAddress = 'osmo1q40xvrzpldwq5he4ftsf7zm2jf80tj373qaven38yqrvhex8r9rs8n94kv'
const testVaultName = 'OSMO-USDC.n'
expect(getVaultMetaData(testAddress)?.name).toBe(testVaultName)
})
})