jquery-calls.js 1.2 KB

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