Created
June 7, 2017 10:02
-
-
Save YoshiyukiKato/01f54528500295229895617ce0922e79 to your computer and use it in GitHub Desktop.
setup browser test environment for mocha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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