change.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. QUnit.test( 'change', function( assert ) {
  2. 'use strict';
  3. var done = assert.async();
  4. function onInitChange() {
  5. assert.ok( false, 'change should not trigger on init' );
  6. }
  7. new Flickity( '#change', {
  8. on: {
  9. change: onInitChange,
  10. ready: function() {
  11. // define events last to first for strict
  12. var onChangeC = function( index ) {
  13. assert.equal( index, 0, 'change triggered on select back to 0' );
  14. done();
  15. };
  16. var onChangeB = function() {
  17. assert.ok( false, 'change should not trigger on same select' );
  18. };
  19. var onSelectB = function( index ) {
  20. assert.equal( index, 1, 'select triggered on same select 1' );
  21. this.off( 'change', onChangeB );
  22. this.once( 'change', onChangeC );
  23. this.select( 0, false, true );
  24. };
  25. var onChangeA = function( index ) {
  26. assert.equal( index, 1, 'change triggered, selected 1');
  27. this.once( 'change', onChangeB );
  28. this.once( 'select', onSelectB );
  29. // select 1 again
  30. this.select( 1, false, true );
  31. };
  32. // kick off
  33. this.off( 'change', onInitChange );
  34. this.once( 'change', onChangeA );
  35. this.select( 1, false, true );
  36. }
  37. },
  38. });
  39. });