File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ import LoginForm from '@/components/LoginForm.vue'
2
+ import { mount } from '@vue/test-utils'
3
+
4
+ describe ( 'LoginForm' , ( ) => {
5
+ it ( 'emits an event with user data payload' , ( ) => {
6
+ const wrapper = mount ( LoginForm )
7
+ const input = wrapper . find ( 'input[type="text"]' ) // Find text input
8
+
9
+ input . setValue ( 'Adam Jahr' ) // Set value for text input
10
+ wrapper . trigger ( 'submit' ) // Simulate form submission
11
+
12
+ // Assert event has been emitted
13
+ const formSubmittedCalls = wrapper . emitted ( 'formSubmitted' )
14
+ expect ( formSubmittedCalls ) . toHaveLength ( 1 )
15
+
16
+ // Assert payload is correct
17
+ const expectedPayload = { name : 'Adam Jahr' }
18
+ expect ( wrapper . emitted ( 'formSubmitted' ) [ 0 ] [ 0 ] ) . toMatchObject (
19
+ expectedPayload
20
+ )
21
+ } )
22
+ } )
You can’t perform that action at this time.
0 commit comments