Jsdom: ReferenceError: Blob is not defined

Created on 16 Apr 2018  ·  3Comments  ·  Source: jsdom/jsdom

Basic info:

  • Node.js version: 6.12.3
  • jsdom version: 11.6.2

Minimal reproduction case

  • Test
import { spy } from "sinon";
import SaveBtn from "../../../app/component/SaveBtn";

const onClickSpy = spy(SaveBtn.prototype, "onClick");

const SaveBtnTest = describe("Testing Submit Button component", function () {
    const SaveBtnElement = renderComponent(SaveBtn);
    ...
    it("should call the submit handler when clicked", function () {
        SaveBtnElement.find("button").simulate("click");
        assert(onClickSpy.calledOnce, true);
    });
});
  • Configuration
const jsdom      = new JSDOM("<!DOCTYPE HTML><html><body></body></html>");
global.window    = jsdom.window;
global.document  = jsdom.window.document;
global.navigator = {
    userAgent: "node.js"
};
...
  • Component
...
onClick() {
    const blob = new Blob([ this.props.code ], {
        type: "text/plain;charset=ascii"
    });
    ...
}

All 3 comments

See https://github.com/jsdom/jsdom/wiki/Don't-stuff-jsdom-globals-onto-the-Node-global. This is the exact problem you're going to run into.

@Sebmaster Thank you so much for your response. I was curious, is there any way I can make sure that the onClick handler method is being called without actually calling it, i.e., using _fake handler_?

There probably is, but that question is more suitable for StackOverflow than here, sorry.

Was this page helpful?
0 / 5 - 0 ratings