-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(core): add test case for utils function * chore: upgrade vitest * test: add tests for the core composition api * chore: update ci * test: update test * test: update test
- Loading branch information
1 parent
4c19b38
commit 5fd36a2
Showing
31 changed files
with
2,815 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
|
||
- name: Set node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
cache: pnpm | ||
|
||
- name: Install | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Lint | ||
run: pnpm lint | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
|
||
- name: Set node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 16.x | ||
cache: pnpm | ||
|
||
- name: Install | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Test | ||
run: pnpm test |
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,5 +1,6 @@ | ||
node_modules | ||
dist | ||
coverage | ||
|
||
.DS_STORE | ||
|
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,56 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { mount } from '@vue/test-utils'; | ||
import { defineComponent } from 'vue'; | ||
|
||
import { useForm, useField } from '../../src'; | ||
|
||
const noop = () => {}; | ||
|
||
const setup = (setup: () => unknown) => { | ||
const Comp = defineComponent({ | ||
setup, | ||
template: `<div />`, | ||
}); | ||
|
||
return mount(Comp); | ||
}; | ||
|
||
describe('useField', () => { | ||
it('when not using it in the correct structure', () => { | ||
setup(() => { | ||
expect(() => useField('name')).toThrowError(); | ||
}); | ||
}); | ||
|
||
it('when useField initialize field value and state', () => { | ||
setup(() => { | ||
useForm({ | ||
initialValues: { | ||
name: 'Alex', | ||
}, | ||
onSubmit: noop, | ||
}); | ||
|
||
const nameField = useField('name'); | ||
expect(nameField.value.value).toEqual('Alex'); | ||
expect(nameField.dirty.value).toEqual(false); | ||
expect(nameField.error.value).toEqual(undefined); | ||
expect(nameField.touched.value).toEqual(false); | ||
expect(nameField.attrs.value.name).toEqual('name'); | ||
|
||
nameField.value.value = 'Hunter'; | ||
expect(nameField.value.value).toEqual('Hunter'); | ||
expect(nameField.dirty.value).toEqual(true); | ||
|
||
const mockEvent = { | ||
target: { | ||
name: 'name', | ||
id: 'name', | ||
}, | ||
} as unknown as Event; | ||
|
||
nameField.attrs.value.onBlur(mockEvent); | ||
expect(nameField.touched.value).toEqual(true); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.