jquery.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. describe('Unit testing jQuery version of easy pie chart', function() {
  2. var $el;
  3. var createInstance = function(options, el) {
  4. options = options || {};
  5. el = el || '<span class="chart"></span>';
  6. return function() {
  7. $el = $(el);
  8. $('body').append($el);
  9. $el.easyPieChart(options);
  10. };
  11. };
  12. describe('initialize plugin', function() {
  13. beforeEach(createInstance());
  14. it('should insert a canvas element', function() {
  15. expect($el.html()).toContain('canvas');
  16. });
  17. });
  18. describe('takes size option and', function() {
  19. var $canvas;
  20. beforeEach(createInstance({
  21. size: 200
  22. }));
  23. beforeEach(function() {
  24. $canvas = $el.find('canvas');
  25. });
  26. it('set correct width', function() {
  27. expect($canvas.width()).toBe(200);
  28. });
  29. it('set correct height', function() {
  30. expect($canvas.height()).toBe(200);
  31. });
  32. });
  33. describe('options should be overwritable by data attributes', function() {
  34. var $canvas;
  35. beforeEach(createInstance({
  36. size: 200
  37. }, '<span class="chart" data-size="400"></span>'));
  38. beforeEach(function() {
  39. $canvas = $el.find('canvas');
  40. });
  41. it('overwrite width', function() {
  42. expect($canvas.width()).toBe(400);
  43. });
  44. it('overwrite height', function() {
  45. expect($canvas.height()).toBe(400);
  46. });
  47. });
  48. });