New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jasmine test case wrapping usage of JsBarCode #114

haxpor opened this Issue Nov 21, 2016 · 2 comments


None yet
2 participants
Copy link

haxpor commented Nov 21, 2016

Possibly not an issue, but I want to make sure.

I create a wrapper over JsBarCode, and I also have jasmine test cases too.

Concept is to add <svg> tag with specified id before render barcode on it. After it finishes, then remove it. I have something like this.

describe("Wrapped Barcode Generator Test", function() {

	var barCode;

	beforeAll(function(done) {
		barCode = Wrapper.barCode; // get JsBarCode API

	describe("Generating Test", function() {
		beforeAll(function() {
			// create a new svg element before each test
			var svg = document.createElement("svg");
			svg.setAttribute("id", "testbarcode1");

		afterAll(function() {
			// remove created svg element after we're done with it
			var svg = document.getElementById("testbarcode1");

		it("should not has any error", function(done) {
			console.log(document.getElementById("testbarcode1"));  // confirm at this line, I have '<svg id="testbarcode1"></svg>'
			var success = true;
			try {
				barCode.generate("#testbarcode1", "dummy");
			catch(e) {
				console.log(e);  // I catch the error from this line
				success = false;


Spotted the creation of error in bin/help/getRenderProperties.js as follows

// If canvas (in node)
else if (element.getContext) {
  return {
    element: element,
    renderer: (0, _renderers.getRendererClass)("canvas")
  } else {
    throw new _exceptions.InvalidElementException();  // this line to create an actual error message we saw

Error it always throws out is Error{name: 'InvalidElementException', message: 'Not supported type to render on'}.

Did I miss something or it doesn't support testing stuff via jasmine?


This comment has been minimized.

Copy link

lindell commented Nov 21, 2016

When creating an SVG element through javascript you can unfortunately not use

var svg = document.createElement("svg");

You have to use

var svg = document.createElementNS("", "svg");

Let me know if that helps :)


This comment has been minimized.

Copy link

haxpor commented Nov 21, 2016

Awesome! Works! Thank you for fast reply :)

@haxpor haxpor closed this Nov 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment