File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
app/code/Magento/Catalog/view/frontend/web/js/product/list
dev/tests/js/jasmine/tests/app/code/Magento/Catalog/frontend/js/product/list Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ define([
3838 /** @inheritdoc */
3939 _create : function ( ) {
4040 if ( isToolbarInitialized ) {
41- return false ;
41+ return ;
4242 }
4343 this . _bind ( $ ( this . options . modeControl ) , this . options . mode , this . options . modeDefault ) ;
4444 this . _bind ( $ ( this . options . directionControl ) , this . options . direction , this . options . directionDefault ) ;
Original file line number Diff line number Diff line change @@ -10,20 +10,37 @@ define([
1010 'use strict' ;
1111
1212 describe ( 'Magento_Catalog/js/product/list/toolbar' , function ( ) {
13- var widget ;
13+ var toolbar ;
1414
1515 beforeEach ( function ( ) {
16- widget = new productListToolbarForm ( ) ;
16+ toolbar = $ ( '<div class="toolbar"></div>' ) ;
17+ } ) ;
18+
19+ afterEach ( function ( ) {
20+ toolbar . remove ( ) ;
1721 } ) ;
1822
1923 it ( 'Widget extends jQuery object' , function ( ) {
2024 expect ( $ . mage . productListToolbarForm ) . toBeDefined ( ) ;
2125 } ) ;
2226
2327 it ( 'Toolbar is initialized' , function ( ) {
24- spyOn ( widget , '_create' ) ;
25- widget . _create ( ) ;
26- expect ( widget . _create ) . toHaveBeenCalled ( ) ;
28+ spyOn ( $ . mage . productListToolbarForm . prototype , '_create' ) ;
29+
30+ toolbar . productListToolbarForm ( ) ;
31+
32+ expect ( $ . mage . productListToolbarForm . prototype . _create ) . toEqual ( jasmine . any ( Function ) ) ;
33+ expect ( $ . mage . productListToolbarForm . prototype . _create ) . toHaveBeenCalledTimes ( 1 ) ;
34+ } ) ;
35+
36+ it ( 'Toolbar is initialized once' , function ( ) {
37+ spyOn ( $ . mage . productListToolbarForm . prototype , '_bind' ) ;
38+
39+ toolbar . productListToolbarForm ( ) ;
40+ var secondToolbar = $ ( '<div class="toolbar"></div>' ) ;
41+ secondToolbar . productListToolbarForm ( ) ;
42+
43+ expect ( $ . mage . productListToolbarForm . prototype . _bind ) . toHaveBeenCalledTimes ( 4 ) ;
2744 } ) ;
2845 } ) ;
2946} ) ;
You can’t perform that action at this time.
0 commit comments