jquery.once.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. (function($) {
  2. /**
  3. * Tests the jQuery Once plugin.
  4. */
  5. Drupal.tests.once = {
  6. getInfo: function() {
  7. return {
  8. name: Drupal.t('jQuery Once'),
  9. description: Drupal.t('Tests for the jQuery Once plugin.'),
  10. group: Drupal.t('System')
  11. };
  12. },
  13. test: function() {
  14. expect(4);
  15. var html = '<span>Hello</span>';
  16. var jqueryhtml = $(html);
  17. // Test One
  18. jqueryhtml.once('testone', function() {
  19. ok(true, Drupal.t('Once function is executed fine.'));
  20. });
  21. jqueryhtml.once('testone', function() {
  22. ok(false, Drupal.t('Once function is executed twice.'));
  23. });
  24. // Test Two
  25. jqueryhtml.once('testtwo', function() {
  26. ok(true, Drupal.t('Once function is executed fine one different tests.'));
  27. });
  28. // Test Three
  29. jqueryhtml.once('newclassfortestthree').addClass('testthreecomplete');
  30. ok(jqueryhtml.hasClass('testthreecomplete'), Drupal.t('Once each function is called.'));
  31. // Test Four
  32. jqueryhtml.once('newclassfortestthree').addClass('failure');
  33. equal(jqueryhtml.hasClass('failure'), false, Drupal.t('Once each function is called multiple times rather then once.'));
  34. }
  35. };
  36. })(jQuery);