• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript jsdom.env函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
                }
            });
        });
开发者ID:swcho,项目名称:ossdb,代码行数:32,代码来源:OpenHubService.ts


示例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();
   });
 });
开发者ID:jannhendrik,项目名称:three-orbitcontrols-ts,代码行数:10,代码来源:index.spec.ts


示例3: reject

 return new Promise<Window>((resolve, reject) => {
     jsdom.env(html, (error, window) => {
         if (error) {
             reject(error);
         }
         else {
             resolve(window);
         }
     });
 });
开发者ID:SaschaNaz,项目名称:webxml,代码行数:10,代码来源:webxml.ts


示例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);
				}
			});
		});
开发者ID:jedmao,项目名称:bindr,代码行数:16,代码来源:Engine.ts


示例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();
    }
  });
});
开发者ID:ompanda,项目名称:gulp-typescript-webpack-react-hotreload,代码行数:17,代码来源:jsdom-helper.ts


示例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 ($)'));
         }
       }
     }
   });
 });
开发者ID:zthomae,项目名称:xanadu,代码行数:21,代码来源:debugSpec.ts


示例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!');
         }
       }
     }
   });
 });
开发者ID:zthomae,项目名称:xanadu,代码行数:23,代码来源:clientSpec.ts


示例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();
        }
    });
});
开发者ID:Microsoft,项目名称:kGrid,代码行数:23,代码来源:unittest.jasmine.spec.ts


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

}
开发者ID:Izhaki,项目名称:gefri,代码行数:68,代码来源:mockDom.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript jsdom.jsdom函数代码示例发布时间:2022-05-25
下一篇:
TypeScript jscodeshift.identifier函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap