File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -90,8 +90,12 @@ export default Base.extend({
9090 // if so, mark both the anchor and the target element
9191 $target . addClass ( "current" ) ;
9292 this . $el . addClass ( "current" ) ;
93+ this . $el . trigger ( "pat-update" , {
94+ pattern : "scroll" ,
95+ action : "attribute-changed" ,
96+ dom : $target [ 0 ] ,
97+ } ) ;
9398 }
94- $ ( this . $el ) . trigger ( "pat-update" , { pattern : "scroll" } ) ;
9599 }
96100 }
97101 }
Original file line number Diff line number Diff line change @@ -220,4 +220,35 @@ describe("pat-scroll", function () {
220220 pat . options . selector = null ; // Using href target
221221 expect ( pat . _get_selector_target ( ) ) . toBe ( el_3 ) ;
222222 } ) ;
223+
224+ it ( "triggers pat-update event." , async ( ) => {
225+ document . body . innerHTML = `
226+ <a href="#el1" class="pat-scroll">scroll to</a>
227+ <div id="el1" />
228+ ` ;
229+
230+ const spy = jest
231+ . spyOn ( utils , "isElementInViewport" )
232+ . mockImplementation ( ( ) => true ) ;
233+
234+ const el = document . querySelector ( ".pat-scroll" ) ;
235+ const target = document . querySelector ( "#el1" ) ;
236+
237+ new pattern ( el ) ;
238+
239+ let data = null ;
240+ $ ( el ) . on ( "pat-update" , ( e , d ) => {
241+ data = d ;
242+ } ) ;
243+
244+ $ ( window ) . scroll ( ) ;
245+ await utils . timeout ( 50 ) ; // wait for debounce.
246+
247+ expect ( data ) . not . toBeNull ( ) ;
248+ expect ( data . pattern ) . toBe ( "scroll" ) ;
249+ expect ( data . action ) . toBe ( "attribute-changed" ) ;
250+ expect ( data . dom ) . toBe ( target ) ;
251+
252+ spy . mockRestore ( ) ;
253+ } ) ;
223254} ) ;
You can’t perform that action at this time.
0 commit comments