@@ -2,62 +2,61 @@ import React from "react"
2
2
import { cleanup , fireEvent , render } from "@testing-library/react"
3
3
import { OutboundLink } from "../"
4
4
5
- describe ( `index.js` , ( ) => {
6
- describe ( `<OutboundLink />` , ( ) => {
7
- afterEach ( ( ) => {
8
- cleanup ( )
9
- jest . resetAllMocks ( )
10
- } )
5
+ describe ( `<OutboundLink />` , ( ) => {
6
+ afterEach ( ( ) => {
7
+ cleanup ( )
8
+ jest . resetAllMocks ( )
9
+ } )
11
10
12
- const setup = props => {
13
- const utils = render ( < OutboundLink { ...props } > link</ OutboundLink > )
11
+ const setup = props => {
12
+ const utils = render ( < OutboundLink { ...props } > link</ OutboundLink > )
14
13
15
- return Object . assign ( { } , utils , {
16
- link : utils . getByText ( `link` ) ,
17
- } )
18
- }
14
+ return Object . assign ( { } , utils , {
15
+ link : utils . getByText ( `link` ) ,
16
+ } )
17
+ }
18
+
19
+ it ( `matches basic snapshot` , ( ) => {
20
+ const { container } = setup ( )
19
21
20
- it ( `matches basic snapshot` , ( ) => {
21
- const { container } = setup ( )
22
+ expect ( container ) . toMatchSnapshot ( )
23
+ } )
22
24
23
- expect ( container ) . toMatchSnapshot ( )
25
+ describe ( `tracking` , ( ) => {
26
+ beforeEach ( ( ) => {
27
+ window . gtag = jest . fn ( )
24
28
} )
29
+ it ( `sends tracking event when clicked` , ( ) => {
30
+ const { link } = setup ( )
25
31
26
- describe ( `tracking` , ( ) => {
27
- beforeEach ( ( ) => {
28
- window . gtag = jest . fn ( )
32
+ fireEvent . click ( link )
33
+
34
+ expect ( window . gtag ) . toHaveBeenCalledTimes ( 1 )
35
+ } )
36
+ it ( `sends custom tracking event when clicked` , ( ) => {
37
+ const eventCategory = `eventcategory`
38
+ const eventAction = `eventaction`
39
+ const eventLabel = `eventlabel`
40
+ const eventValue = 55
41
+ const { link } = setup ( {
42
+ eventCategory,
43
+ eventAction,
44
+ eventLabel,
45
+ eventValue,
29
46
} )
30
- it ( `sends tracking event when clicked` , ( ) => {
31
- const { link } = setup ( )
32
47
33
- fireEvent . click ( link )
48
+ fireEvent . click ( link )
34
49
35
- expect ( window . gtag ) . toHaveBeenCalled ( )
36
- } )
37
- it ( `sends custom tracking event when clicked` , ( ) => {
38
- const eventCategory = `eventcategory`
39
- const eventAction = `eventaction`
40
- const eventLabel = `eventlabel`
41
- const eventValue = 55
42
- const { link } = setup ( {
43
- eventCategory,
44
- eventAction,
45
- eventLabel,
46
- eventValue,
50
+ expect ( window . gtag ) . toHaveBeenCalledTimes ( 1 )
51
+ expect ( window . gtag ) . toHaveBeenCalledWith (
52
+ `event` ,
53
+ eventAction ,
54
+ expect . objectContaining ( {
55
+ event_category : eventCategory ,
56
+ event_label : eventLabel ,
57
+ event_value : eventValue ,
47
58
} )
48
-
49
- fireEvent . click ( link )
50
-
51
- expect ( window . gtag ) . toHaveBeenCalledWith (
52
- `event` ,
53
- eventAction ,
54
- expect . objectContaining ( {
55
- event_category : eventCategory ,
56
- event_label : eventLabel ,
57
- event_value : eventValue ,
58
- } )
59
- )
60
- } )
59
+ )
61
60
} )
62
61
} )
63
62
} )
0 commit comments