当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript jsdom.jsdom函数代码示例

本文整理汇总了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');
 });
开发者ID:richardy2012,项目名称:cafe-pitch,代码行数:7,代码来源:input_editor.story.ts

示例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 !!!');
}
开发者ID:mathieuancelin,项目名称:react-typescript-template,代码行数:15,代码来源:bootstrap.ts

示例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;
    });

  });

});
开发者ID:bbaaxx,项目名称:vanilla-json-menumaker,代码行数:47,代码来源:MenuMaker.spec.ts

示例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);
    });
}
开发者ID:andrewwcaldwell,项目名称:ChatFaces,代码行数:25,代码来源:hlight.original.ts

示例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]
  }
}
开发者ID:jaystack,项目名称:electron-react-typescript,代码行数:27,代码来源:dom.ts

示例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);
开发者ID:chun4foryou,项目名称:develop,代码行数:9,代码来源:jsdom-test.ts

示例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;
      }
    });
  });
}
开发者ID:JeroenVinke,项目名称:pal-nodejs,代码行数:67,代码来源:index.ts

示例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);
开发者ID:nicholasceliano,项目名称:AJLocationTracker,代码行数:31,代码来源:app.ts

示例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];
  }
});
开发者ID:NYPL-Simplified,项目名称:circulation-patron-web,代码行数:15,代码来源:testHelper.ts

示例10: jsdom

export const bootstrap = () => {
    const doc = jsdom('<!doctype html><html><body></body></html>')
    global.document = doc
    global.window = doc.defaultView
}
开发者ID:cantide5ga,项目名称:pluto-rd,代码行数:5,代码来源:Dom.ts


注:本文中的jsdom.jsdom函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。