@@ -45,18 +45,18 @@ const DispatchButton = ({ testId = 'dispatch-btn' }: DispatchButton) => {
4545} ;
4646
4747describe ( 'Element' , ( ) => {
48- it ( 'should attach the element property when dispatching an event' , ( ) => {
48+ it ( 'should append the name to the elementTree when dispatching an event' , ( ) => {
4949 const dispatch = jest . fn ( ) ;
5050 const app = '' ;
5151 const view = 'test' ;
52- const element = 'test-element-spec ' ;
52+ const name = 'test-element' ;
5353 const btn = 'dispatch-btn' ;
5454 const component = 'button' ;
5555
5656 const expected = {
5757 app,
5858 view,
59- elementTree : [ element ] ,
59+ elementTree : [ name ] ,
6060 event : Events . click ,
6161 component,
6262 label : undefined ,
@@ -66,7 +66,41 @@ describe('Element', () => {
6666 const { getByTestId } = render (
6767 < TrackingRoot name = { app } onDispatch = { dispatch } >
6868 < TrackingView name = { view } >
69- < TrackingElement name = { element } >
69+ < TrackingElement name = { name } >
70+ < DispatchButton />
71+ </ TrackingElement >
72+ </ TrackingView >
73+ </ TrackingRoot >
74+ ) ;
75+
76+ fireEvent . click ( getByTestId ( btn ) ) ;
77+
78+ expect ( dispatch ) . toHaveBeenCalledWith ( expected ) ;
79+ } ) ;
80+
81+ it ( 'should append the name and label to the elementTree when dispatching an event' , ( ) => {
82+ const dispatch = jest . fn ( ) ;
83+ const app = '' ;
84+ const view = 'test' ;
85+ const name = 'test-element' ;
86+ const label = 'test-label' ;
87+ const btn = 'dispatch-btn' ;
88+ const component = 'button' ;
89+
90+ const expected = {
91+ app,
92+ view,
93+ elementTree : [ 'test-element|test-label' ] ,
94+ event : Events . click ,
95+ component,
96+ label : undefined ,
97+ timestamp : expect . any ( Number )
98+ } ;
99+
100+ const { getByTestId } = render (
101+ < TrackingRoot name = { app } onDispatch = { dispatch } >
102+ < TrackingView name = { view } >
103+ < TrackingElement name = { name } label = { label } >
70104 < DispatchButton />
71105 </ TrackingElement >
72106 </ TrackingView >
0 commit comments