forked from vu3th/vue-dapp
-
Notifications
You must be signed in to change notification settings - Fork 0
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
46499f3
commit 39af1cc
Showing
9 changed files
with
547 additions
and
1,337 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
This file was deleted.
Oops, something went wrong.
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,46 @@ | ||
import { mount } from '@vue/test-utils' | ||
import Board from '@/components/Board.vue' | ||
import Modal from '@/components/Modal.vue' | ||
import Loader from '@/components/Loader.vue' | ||
import { MetaMaskConnector, Connector } from '@/connectors' | ||
const connectors: Connector[] = [new MetaMaskConnector()] | ||
|
||
describe('Board component', () => { | ||
beforeEach(() => { | ||
// create teleport target | ||
const el = document.createElement('div') | ||
el.id = 'modal' | ||
document.body.appendChild(el) | ||
}) | ||
|
||
afterEach(() => { | ||
// clean up | ||
document.body.outerHTML = '' | ||
}) | ||
it('should work with import on demand', () => { | ||
// mount(Loader) | ||
// mount(Modal, { | ||
// propsData: { | ||
// modalOpen: true, | ||
// }, | ||
// }) | ||
const wrapper = mount(Board, { | ||
attachTo: document.body, | ||
propsData: { | ||
connectors: connectors, | ||
}, | ||
global: { | ||
stubs: { | ||
teleport: true, | ||
}, | ||
}, | ||
// provide: { | ||
// autoConnect() { | ||
// return false | ||
// }, | ||
// }, | ||
}) | ||
// console.warn(wrapper.getComponent(Board).html()) | ||
expect(wrapper.getComponent(Board).html()).toContain('MetaMask') | ||
}) | ||
}) |
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,32 @@ | ||
import { mount } from '@vue/test-utils' | ||
import { defineComponent, nextTick, ref } from 'vue' | ||
import { useWallet } from '@/composables' | ||
|
||
// wip: refer to https://github.com/Mini-ghost/vorms/blob/main/packages/core/tests/composiable/useForm.test.ts | ||
|
||
const noop = () => {} | ||
|
||
const setup = (setup: () => unknown) => { | ||
const Comp = defineComponent({ | ||
setup, | ||
template: `<div />`, | ||
}) | ||
|
||
return mount(Comp) | ||
} | ||
|
||
const sleep = (ms?: number) => { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} | ||
|
||
describe('useWallet', () => { | ||
it('when initialize wallet state', () => { | ||
setup(() => { | ||
const { wallet } = useWallet() | ||
expect(wallet.connector).toEqual(null) | ||
expect(wallet.error).toEqual('') | ||
expect(wallet.provider).toEqual(null) | ||
expect(wallet.status).toEqual('none') | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { checkChainId } from '@/utils' | ||
|
||
describe('checkChainId', () => { | ||
it('should return true when chain id is in the available network', () => { | ||
expect(checkChainId(1)).toBeTruthy() | ||
expect(checkChainId(5)).toBeTruthy() | ||
}) | ||
it('should return false when chain id is not in the available network', () => { | ||
expect(checkChainId(2)).toBeFalsy() | ||
expect(checkChainId(4)).toBeFalsy() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineConfig } from 'vitest/config' | ||
import path from 'path' | ||
import vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [vue()], | ||
define: { | ||
__DEV__: true, | ||
}, | ||
test: { | ||
globals: true, // no need to import test api like `import { describe, expect, it } from 'vitest'` | ||
environment: 'jsdom', | ||
include: ['tests/**/*.test.ts'], | ||
}, | ||
resolve: { | ||
alias: { | ||
'@': path.resolve(__dirname, './src'), | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.