data-tests.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. module('Options - Attributes');
  2. var $ = require('jquery');
  3. var Options = require('select2/options');
  4. test('no nesting', function (assert) {
  5. var $test = $('<select data-test="test"></select>');
  6. var options = new Options({}, $test);
  7. assert.equal(options.get('test'), 'test');
  8. });
  9. test('with nesting', function (assert) {
  10. var $test = $('<select data-first--second="test"></select>');
  11. if ($test[0].dataset == null) {
  12. assert.ok(
  13. true,
  14. 'We can not run this test with jQuery 1.x if dataset is not implemented'
  15. );
  16. return;
  17. }
  18. var options = new Options({}, $test);
  19. assert.ok(!(options.get('first-Second')));
  20. assert.equal(options.get('first').second, 'test');
  21. });
  22. test('overrides initialized data', function (assert) {
  23. var $test = $('<select data-override="yes" data-data="yes"></select>');
  24. var options = new Options({
  25. options: 'yes',
  26. override: 'no'
  27. }, $test);
  28. assert.equal(options.get('options'), 'yes');
  29. assert.equal(options.get('override'), 'yes');
  30. assert.equal(options.get('data'), 'yes');
  31. });