@@ -4,57 +4,58 @@ import ListComponent from '@/list.vue'
4
4
5
5
/*When testing vue.js components, need a way to mount and render the component; use the mount function. Mount
6
6
creates a Wrapper containing the mounted and rendered Vue component. */
7
- it ( 'should mount a vue TestComponent ', ( ) => {
8
- const wrapper = mount ( TestComponent ) ;
9
- console . log ( "TestComponent wrapper: " + wrapper ) ;
10
- expect ( wrapper . text ( ) ) . toContain ( "Hello Test" ) ;
11
-
12
- //Wrapper HTML function returns the entire component DOM node as a string. toMatchSnapshot() creates a snapshot
13
- // of the component in the __snapshots__ dir. To learn more about snapshots, check out Snapshot Testing with Jest
14
- // at Vue School, but this class is not free.
15
- //debugger;
16
- expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
17
- console . log ( "TestComponent wrapper html(): " + wrapper . html ( ) ) ;
18
- expect ( wrapper . html ( ) ) . toContain ( "<h1>Hello Test</h1>" ) ;
19
- } ) ;
20
-
21
- it ( 'should override the default value to say Hello to in the TestComponent' , ( ) => {
22
- const wrapper = mount ( TestComponent ,
23
- {
24
- propsData : { value : 'VueSchool' }
25
- } ) ;
26
- expect ( wrapper . text ( ) ) . toContain ( "Hello VueSchool" ) ;
27
-
28
- expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
29
- console . log ( "Overriden TestComponent wrapper html(): " + wrapper . html ( ) ) ;
30
- expect ( wrapper . html ( ) ) . toContain ( "<h1>Hello VueSchool</h1>" ) ;
31
- } ) ;
32
-
33
- it ( 'should shallowMount the ListComponent' , ( ) => {
34
- // shallowMount() and mount() are almost the same except child components of the one comp u shallowMounted get
35
- // stubbed automatically. Use mount() as much as pos as the default approach as it helps to find issues in child
36
- // comps early.
37
- console . log ( "Log of mount(ListComponent): " + mount ( ListComponent ) . html ( ) ) ;
38
- const wrapper = shallowMount ( ListComponent ) ;
39
- console . log ( "Log of shallowMount(ListComponent): " + wrapper . html ( ) ) ;
40
- //shallowMount() should stub out the list items in the list
41
- expect ( wrapper . html ( ) ) . toContain ( '<listitem-stub movie="Iron Man"></listitem-stub>' ) ;
42
- } ) ;
7
+ describe ( 'TestComponent and ListComponent Tests ', ( ) => {
8
+
9
+ it ( 'should mount a vue TestComponent' , ( ) => {
10
+ const wrapper = mount ( TestComponent ) ;
11
+ console . log ( "TestComponent wrapper: " + wrapper ) ;
12
+ expect ( wrapper . text ( ) ) . toContain ( "Hello Test" ) ;
13
+
14
+ //Wrapper HTML function returns the entire component DOM node as a string. toMatchSnapshot() creates a snapshot
15
+ // of the component in the __snapshots__ dir. To learn more about snapshots, check out Snapshot Testing with Jest
16
+ // at Vue School, but this class is not free.
17
+ //debugger ;
18
+ expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
19
+ console . log ( "TestComponent wrapper html(): " + wrapper . html ( ) ) ;
20
+ expect ( wrapper . html ( ) ) . toContain ( "<h1>Hello Test</h1>" ) ;
21
+ } ) ;
22
+
23
+ it ( 'should override the default value to say Hello to in the TestComponent' , ( ) => {
24
+ const wrapper = mount ( TestComponent ,
25
+ { propsData : { value : 'VueSchool' } } ) ;
26
+ expect ( wrapper . text ( ) ) . toContain ( "Hello VueSchool" ) ;
27
+
28
+ expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
29
+ console . log ( "Overriden TestComponent wrapper html(): " + wrapper . html ( ) ) ;
30
+ expect ( wrapper . html ( ) ) . toContain ( "<h1>Hello VueSchool</h1>" ) ;
31
+ } ) ;
32
+
33
+ it ( 'should shallowMount the ListComponent' , ( ) => {
34
+ // shallowMount() and mount() are almost the same except child components of the one comp u shallowMounted get
35
+ // stubbed automatically. Use mount() as much as pos as the default approach as it helps to find issues in child
36
+ // comps early.
37
+ console . log ( "Log of mount(ListComponent): " + mount ( ListComponent ) . html ( ) ) ;
38
+ const wrapper = shallowMount ( ListComponent ) ;
39
+ console . log ( "Log of shallowMount(ListComponent): " + wrapper . html ( ) ) ;
40
+ //shallowMount() should stub out the list items in the list
41
+ expect ( wrapper . html ( ) ) . toContain ( '<listitem-stub movie="Iron Man"></listitem-stub>' ) ;
42
+ } ) ;
43
43
44
44
//Wrapper properties --> most important one is VM. It gives access to the Vue instance, the same instance you could
45
45
// interact w/ from the browser console.
46
- it ( 'should add a list item to the ListComponent' , ( ) => {
47
- const wrapper = mount ( ListComponent ) ;
48
- //Need to get the current set of data in list.vue, which we can get from the wrapper's VM property:
49
- //let movies = wrapper.vm.marvelMovies;
50
-
51
- //Now, use setData() to update the actual data set.
52
- wrapper . setData ( { marvelMovies : [ ...wrapper . vm . marvelMovies , 'Endgame' ] } ) ;
53
- //this above does update the data set/list, but not in the snapshot file (test.spec.js.snap)
54
- //can see the update in the following log
55
- console . log ( "marvelMovies: " + wrapper . vm . marvelMovies ) ;
56
-
57
- expect ( wrapper . vm . marvelMovies ) . toContain ( 'Endgame' ) ;
58
- expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
46
+ it ( 'should add a list item to the ListComponent' , ( ) => {
47
+ const wrapper = mount ( ListComponent ) ;
48
+ //Need to get the current set of data in list.vue, which we can get from the wrapper's VM property:
49
+ //let movies = wrapper.vm.marvelMovies;
50
+
51
+ //Now, use setData() to update the actual data set.
52
+ wrapper . setData ( { marvelMovies : [ ...wrapper . vm . marvelMovies , 'Endgame' ] } ) ;
53
+ //this above does update the data set/list, but not in the snapshot file (test.spec.js.snap)
54
+ //can see the update in the following log
55
+ console . log ( "marvelMovies: " + wrapper . vm . marvelMovies ) ;
56
+
57
+ expect ( wrapper . vm . marvelMovies ) . toContain ( 'Endgame' ) ;
58
+ expect ( wrapper . html ( ) ) . toMatchSnapshot ( ) ;
59
+ } ) ;
59
60
} ) ;
60
61
0 commit comments