Object-Render.test.js 946 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var assert = require('assert');
  2. var JsBarcode = require('../../bin/JsBarcode.js');
  3. var Canvas = require("canvas");
  4. describe('Object', function() {
  5. it('should handle default options', function () {
  6. var data = {};
  7. JsBarcode(data, '12345678');
  8. assert.equal(typeof data.encodings, 'object');
  9. });
  10. it('should catch null', function() {
  11. assert.throws(
  12. () => {
  13. JsBarcode(null, '12345678');
  14. },
  15. /InvalidElementException/
  16. );
  17. });
  18. it('should ignore dom elements', function() {
  19. var fakeElement = {
  20. nodeName: 'Some Dom Element'
  21. }
  22. assert.throws(
  23. () => {
  24. JsBarcode(fakeElement, '2345678');
  25. },
  26. /InvalidElementException/
  27. );
  28. });
  29. it('should work for different types', function () {
  30. var data = {};
  31. JsBarcode(data, '550000000000', {
  32. format: 'upc'
  33. });
  34. assert.equal(data.encodings.length, 7);
  35. assert.ok(data.encodings.every((val) => val.options.format === 'upc'));
  36. });
  37. });