jquery-calls.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. module('select2(val)');
  2. test('multiple elements with arguments works', function (assert) {
  3. var $ = require('jquery');
  4. require('jquery.select2');
  5. var $first = $(
  6. '<select>' +
  7. '<option>1</option>' +
  8. '<option>2</option>' +
  9. '</select>'
  10. );
  11. var $second = $first.clone();
  12. var $both = $first.add($second);
  13. $both.select2();
  14. $both.select2('val', '2');
  15. assert.equal(
  16. $first.val(),
  17. '2',
  18. 'The call should change the value on the first element'
  19. );
  20. assert.equal(
  21. $second.val(),
  22. '2',
  23. 'The call should also change the value on the second element'
  24. );
  25. });
  26. test('initializes when jQuery $.data contains' +
  27. ' cyclic reference', function (assert) {
  28. var $ = require('jquery');
  29. require('jquery.select2');
  30. var $select = $(
  31. '<select>' +
  32. '<option>One</option>' +
  33. '<option>Two</option>' +
  34. '<option value="3" selected>Three</option>' +
  35. '</select>'
  36. );
  37. // Add a circular reference object using jQuery.
  38. var recursiveObject = {};
  39. recursiveObject.same = recursiveObject;
  40. $select.data('same', recursiveObject);
  41. $select.select2();
  42. assert.equal(
  43. $select.val(),
  44. '3',
  45. 'The option value should be pulled correctly'
  46. );
  47. });