本文整理匯總了TypeScript中jsdom.jsdom函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript jsdom函數的具體用法?TypeScript jsdom怎麽用?TypeScript jsdom使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了jsdom函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: jsdom
.then((html) => {
const dom: Document = jsdom(html);
const h1 = dom.querySelector('h1');
assert.equal(h1.textContent, 'h1 title');
const h2 = dom.querySelector('h2');
assert.equal(h2.textContent, 'h2 title');
});
示例2: bootstrapEnv
export function bootstrapEnv(body = '') {
const doc = jsdom.jsdom(`<!doctype html><html><body>${body}</body></html>`);
const win = doc.defaultView;
function propagateToGlobal(window) {
for (const key in window) {
if (!window.hasOwnProperty(key)) continue;
if (key in global) continue;
global[key] = window[key];
}
}
global.document = doc;
global.window = win;
propagateToGlobal(win);
console.log('\nENV setup is done !!!');
}
示例3: describe
describe('MenuMaker class', ()=> {
// Set up the DOM
interface GlobalWindow extends NodeJS.Global { document? : any; }
(global as GlobalWindow).document = jsdomJsdom('<html><body></body></html>');
let mockElement : HTMLElement;
let mockItems : MenuItem[];
let testInstance : MenuMaker;
beforeEach(()=>{
mockElement = document.createElement('div');
mockItems = [new MenuItem({
id: 'theId',
index: 1,
href: 'www.example.com',
name: 'theName'
})]
});
afterEach(()=>{
mockElement = null;
mockItems = null;
testInstance = null;
});
it('Should create an instance of MenuMaker', ()=> {
testInstance = new MenuMaker(mockElement, mockItems);
expect(testInstance).to.exist;
expect(testInstance).to.be.an.instanceOf(MenuMaker);
});
describe('deployMarkup method', function() {
beforeEach(()=>{
testInstance = new MenuMaker(mockElement, mockItems);
});
it('Should render the menu items in the target element', ()=> {
expect(mockElement.childNodes).to.be.empty;
testInstance.deployMarkup();
expect(mockElement.childNodes).to.not.be.empty;
});
});
});
示例4: htmlout
/**
* Takes in HTML and writes out text w/ escape sequences to style the text for
* console output.
*
* By default this method writes directly to the console. To do something
* different (e.g. to write to a string) you can supply your own writer object
* (anything with a `write` method) in the options.
*/
function htmlout(html, options) {
var doc = jsdom('<html><head></head><body></body></html>');
options.writer = new ConsoleWriter();
options.css.unshift(defaultStylesheet);
options.css.forEach(function(css) {
var styleNode = doc.createElement('STYLE');
styleNode.textContent = css;
doc.head.appendChild(styleNode);
});
doc.body.innerHTML = html;
var buffer = [];
forEach(doc.body.childNodes, function(node) {
output(node, buffer, options.writer);
});
}
示例5: require
const jsdom = require('jsdom') // tslint:disable-line
// setup the simplest document possible
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>')
// get the window object out of the document
const win = doc.defaultView
// set globals for mocha that make access to document and window feel
// natural in the test environment
const g: any = global
g.document = doc
g.window = win
// take all properties of the window object and also attach it to the
// mocha global object
propagateToGlobal(win)
// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
function propagateToGlobal (window) {
for (let key in window) {
if (!window.hasOwnProperty(key)) continue
if (key in global) continue
global[key] = window[key]
}
}
示例6: require
let jsdom = require("jsdom").jsdom;
import fs = require("fs");
let html = fs.readFileSync("src/dom/index.html", "utf-8");
let doc = jsdom(html);
let window = doc.defaultView;
console.log(window.document.documentElement.outerHTML);
console.log(window.innerWidth);
console.log(typeof window.document.getElementsByClassName);
示例7: initialize
export function initialize(): void {
if (isInitialized) {
return;
}
isInitialized = true;
//_ensureCustomEvent();
//_ensureFunctionName();
//_ensureHTMLTemplateElement();
//_ensureElementMatches();
//_ensureClassList();
//_ensurePerformance();
var global:IGlobal = jsdom(undefined, {}).defaultView;
var _platform = new NodeJsPlatform(global);
var _dom = new NodeJsDom(global);
initializePAL((platform, feature, dom) => {
Object.assign(platform, _platform);
//Object.assign(feature, _FEATURE);
Object.assign(dom, _dom);
(function(global) {
global.console = global.console || {};
let con = global.console;
let prop;
let method;
let empty = {};
let dummy = function() {};
let properties = 'memory'.split(',');
let methods = ('assert,clear,count,debug,dir,dirxml,error,exception,group,' +
'groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,' +
'show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn').split(',');
while (prop = properties.pop()) if (!con[prop]) con[prop] = empty;
while (method = methods.pop()) if (!con[method]) con[method] = dummy;
})(platform.global);
if (platform.global.console && typeof console.log === 'object') {
['log', 'info', 'warn', 'error', 'assert', 'dir', 'clear', 'profile', 'profileEnd'].forEach(function(method) {
console[method] = this.bind(console[method], console);
}, Function.prototype.call);
}
Object.defineProperty(dom, 'title', {
get: function() {
return document.title;
},
set: function(value) {
document.title = value;
}
});
Object.defineProperty(dom, 'activeElement', {
get: function() {
return document.activeElement;
}
});
Object.defineProperty(platform, 'XMLHttpRequest', {
get: function() {
return platform.global.XMLHttpRequest;
}
});
});
}
示例8: require
///<reference path='public/javascripts/typings/node.d.ts' />
///<reference path='public/javascripts/typings/jquery.d.ts' />
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var bodyParser = require('body-parser');
var app = express();
var routes = require('./routes/index');
var server = require('http').Server(app);
var sIO = require('socket.io')(server);
var jsdom = require("jsdom");
var $: JQueryStatic = require("jquery")(jsdom.jsdom().createWindow());
var gm = require('googlemaps');
gm.config({ key: 'AIzaSyDIUHVyHjABaBnF2h2yROpJCroqRSzZFXg' });
var loadData = require('./serverCode/sLoadData');
var empList = loadData.EmpDataLoad();
var jobList = loadData.JobDataLoad();
var businessList = loadData.BusinessDataLoad();
module sMain {
sIO.on('connection', function (socket) {
var cHead = socket.handshake.headers;
var pageAccessed: string = cHead.referer.split(cHead.host)[1];
switch (pageAccessed) {
case '/':
var markerList = loadData.BuildMarkerList(empList, jobList, businessList);
sIO.emit('loadInitialMap', markerList);
示例9: jsdom
import "./ignore_stylesheet_imports";
import { jsdom } from "jsdom";
const doc = jsdom("<!doctype html><html><body></body></html>");
const win = doc.defaultView;
global["document"] = doc;
global["window"] = win;
Object.keys(window).forEach((key) => {
if (!(key in global)) {
global[key] = window[key];
}
});
示例10: jsdom
export const bootstrap = () => {
const doc = jsdom('<!doctype html><html><body></body></html>')
global.document = doc
global.window = doc.defaultView
}