Skip to content

Instantly share code, notes, and snippets.

@YoshiyukiKato
Created June 7, 2017 10:02
Show Gist options
  • Save YoshiyukiKato/01f54528500295229895617ce0922e79 to your computer and use it in GitHub Desktop.
Save YoshiyukiKato/01f54528500295229895617ce0922e79 to your computer and use it in GitHub Desktop.
setup browser test environment for mocha
import {jsdom} from "jsdom";
import * as jquery from "jquery";
declare global{
interface Window{
XMLHttpRequest:XMLHttpRequest;
}
namespace NodeJS{
interface Global {
jsdom?: any;
sinon?: any;
$?:JQuery;
document?: Document;
window?:Window;
XMLHttpRequest?:XMLHttpRequest;
navigator?:Navigator;
}
}
}
global.jsdom = jsdom;
global.document = global.jsdom('<!doctype html><html><body></body></html>');
global.window = global.document.defaultView;
global.XMLHttpRequest = global.window.XMLHttpRequest;
global.navigator = window.navigator;
import * as sinon from "sinon";
global.sinon = sinon;
global.sinon.useFakeXMLHttpRequest();
global.window.XMLHttpRequest = global.XMLHttpRequest;
global.$ = jquery(global.window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment