Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 5e8211d

Browse files
committed
feat(e2e): added test for reset after submission demo
1 parent 4c22d09 commit 5e8211d

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@vue/compiler-sfc": "3.0.2",
4747
"@vue/eslint-config-prettier": "^6.0.0",
4848
"@vue/eslint-config-typescript": "^7.0.0",
49-
"@vue/test-utils": "^2.0.0-beta.14",
49+
"@vue/test-utils": "^2.0.0-rc.0",
5050
"babel-core": "7.0.0-bridge.0",
5151
"babel-eslint": "10.1.0",
5252
"babel-jest": "26.6.3",
@@ -77,7 +77,7 @@
7777
"typescript": "~4.1.2",
7878
"vue": "^3.0.0",
7979
"vue-cli-plugin-cypress-experimental": "~1.2.0",
80-
"vue-jest": "^5.0.0-alpha.7",
80+
"vue-jest": "^5.0.0-alpha.8",
8181
"vue-router": "^4.0.1",
8282
"vue-select": "3.10.8"
8383
},

src/composables/useDynamicForm.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ describe('UseDynamicForm', () => {
188188
rememberMe: true,
189189
});
190190
});
191+
// TODO: check this after on how to spy on functions inside functions
192+
/*
193+
it('should reset form after valid form submission', async () => {
194+
const { mapControls, handleSubmit, resetForm } = useDynamicForm(form, ctx);
195+
const spy = jest.spyOn({ resetForm }, 'resetForm');
196+
mapControls();
197+
198+
await handleSubmit();
199+
200+
expect(spy).toHaveBeenCalled();
201+
}); */
191202

192203
it('should emit error event with errors if hadleSubmit is called and is form is invalid ', async () => {
193204
const spy = jest.spyOn(ctx, 'emit');

src/composables/useDynamicForm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ export function useDynamicForm(
6060

6161
const controls: Ref<FormControl<InputType>[]> = ref([]);
6262
const formOptions: Ref<FormOptions> = ref({
63+
resetAfterSubmit: true,
6364
...options?.form,
6465
...form?.options,
65-
resetAfterSubmit: true,
6666
});
6767
const forceValidation = ref(false);
6868

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
describe('Reset after submission', () => {
2+
beforeEach(() => {
3+
cy.visit('/reset-after-submit'); // "baseUrl" is defined in cypress.json file
4+
});
5+
6+
context('Basic Events', () => {
7+
it('should reset the form if resetAfterSubmit is checked', () => {
8+
cy.get('input[name="resetAfterSubmit"]').check();
9+
cy.get('[data-cy=submit]').click();
10+
cy.get('input[name="name"]').should('not.have.value', null);
11+
});
12+
13+
it('should reset the form if resetAfterSubmit is unchecked', () => {
14+
cy.get('input[name="resetAfterSubmit"]').uncheck();
15+
cy.get('[data-cy=submit]').click();
16+
cy.get('input[name="name"]').should('have.value', 'Awiwiwi');
17+
});
18+
});
19+
});

0 commit comments

Comments
 (0)