本文整理汇总了TypeScript中jsdom.env函数的典型用法代码示例。如果您正苦于以下问题:TypeScript env函数的具体用法?TypeScript env怎么用?TypeScript env使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了env函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
}, function(error: any, response: any, body: any) {
var licenseInfo: TLicenseInfo = {
name: '',
abbreviation: '',
homepage: '',
licenseText: ''
};
jsdom.env({
html: body,
scripts: [jqueryPath],
// scripts: ['http://code.jquery.com/jquery-1.6.min.js'],
done: function(err, window){
//Use jQuery just as in a regular HTML page
var $ = window.jQuery;
var title = $('#license').find('h1 a[title]').attr('title');
var match = /(.*)\((.+)\)/.exec(title);
if (match) {
licenseInfo.name = trim(match[1]);
licenseInfo.abbreviation = trim(match[2]);
} else {
licenseInfo.name = trim(title);
}
var $licenseUrlLabel = $('p:contains("Read more about this license")');
licenseInfo.homepage = $licenseUrlLabel.children('a').attr('href');
var licenseText = $licenseUrlLabel.prev().text();
licenseInfo.licenseText = licenseText.indexOf('Provide') == 0 ? '' : licenseText;
cb(err, licenseInfo);
}
});
});
示例2: beforeEach
beforeEach((done) => {
const camera = new THREE.PerspectiveCamera(50, 2, 1, 1000);
const document = jsdom.env('<html><body><div id="container"></div></body></html>', (err, _window_) => {
if (err) return done(err);
window = _window_;
container = window.document.getElementById( 'container' );
controls = new OrbitControls(camera, container, window);
done();
});
});
示例3: reject
return new Promise<Window>((resolve, reject) => {
jsdom.env(html, (error, window) => {
if (error) {
reject(error);
}
else {
resolve(window);
}
});
});
示例4:
fs.readFile(this.scriptPath, { encoding: 'utf-8' }, (err, lib) => {
if (err) {
throw err;
}
jsdom.env({
html: source || '<html><body></body></html>',
src: [lib],
features: {
FetchExternalResources: false,
ProcessExternalResources: false
},
done: (errors, window) => {
willLoadWindow.resolve(window);
}
});
});
示例5: beforeEach
beforeEach(done => {
jsdom.env({
html: '<!doctype html><html><body></body></html>',
scripts: [],
done(err, createdWindow) {
if (err) {
return done(err);
}
global['window'] = createdWindow;
global['document'] = createdWindow.document;
global['navigator'] = createdWindow.navigator;
done();
}
});
});
示例6: reject
return clientPromise = new Promise<Window>((resolve, reject) => {
jsdom.env({
file: htmlPath,
scripts: [ jQueryPath, bootstrapPath ],
done: (error, window) => {
if (error) {
reject(error);
} else {
const w = window as any;
// Can we use jQuery?
if (w.$) {
w.$(window.document).ready(() => {
resolve(window);
});
} else {
reject(new Error('Window does not have global jQuery ($)'));
}
}
}
});
});
示例7: Error
clientPromise = new Promise<WindowAndJQuery>((resolve) => {
// XXX: should virtualConsole be set?
jsdom.env({
file: htmlPath,
scripts: [jqueryPath, bootstrapPath],
done: (error, window) => {
if (error) {
throw error;
} else {
if ((window as any).$) {
(window as any).$(window.document).ready(function () {
resolve({
window,
$: (window as any).$
});
});
} else {
throw new Error('jQuery not attached to window!');
}
}
}
});
});
示例8: beforeEach
beforeEach(function(done) {
if ($) {
done();
return;
}
var fs = require('fs')
var jsdom = require('jsdom');
jsdom.env({
html: '<html><body></body></html>',
src: [
fs.readFileSync('install/lib/jquery/jquery.js', 'utf-8'),
fs.readFileSync('install/js/listcontrol.js', 'utf-8')
],
done: function (err, window) {
$ = window.jQuery;
MSOC = window.Microsoft.Office.Controls;
done();
}
});
});
示例9: mockDom
function mockDom( aScriptFiles, aDoneCallback ) {
let scripts = loadScripts( aScriptFiles );
jsdom.env({
html: `<html><body><div id="${ VIEW_ELEMENT_ID }" style="width:500px; height:400px;"></div></body></html>`,
src: scripts,
done: onDomLoaded
});
function loadScripts( aScriptFiles ) {
var iScripts = [];
aScriptFiles.forEach( function( aScriptFile ){
var iScript = fs.readFileSync( aScriptFile, 'utf-8' );
iScripts.push( iScript );
});
return iScripts;
}
function onDomLoaded( aError, aWindow ) {
if ( aError ) {
throw new Error( aError )
} else {
mockContext( aWindow.document );
overrideOffsetGetters( aWindow );
setGlobals( aWindow );
}
aDoneCallback();
}
function mockContext( aDocument ) {
var originalCreateElement = aDocument.createElement;
aDocument.createElement = function( tagName ) {
var element = originalCreateElement.call( aDocument, tagName );
if ( tagName.toLowerCase() === 'canvas' ) {
element.getContext = function() {
return new Context2DMock();
}
}
return element;
};
}
function overrideOffsetGetters( aWindow ) {
Object.defineProperties( aWindow.HTMLElement.prototype, {
offsetLeft: {
get: function() { return parseFloat( aWindow.getComputedStyle(this).left) || 0; }
},
offsetTop: {
get: function() { return parseFloat( aWindow.getComputedStyle(this).top) || 0; }
},
offsetHeight: {
get: function() { return parseFloat( aWindow.getComputedStyle(this).height) || 0; }
},
offsetWidth: {
get: function() { return parseFloat( aWindow.getComputedStyle(this).width) || 0; }
}
});
}
function setGlobals( aWindow ) {
global.window = aWindow;
global.document = aWindow.document;
global.gefri = aWindow.gefri;
}
}