本文整理汇总了TypeScript中jsdom.JSDOM类的典型用法代码示例。如果您正苦于以下问题:TypeScript JSDOM类的具体用法?TypeScript JSDOM怎么用?TypeScript JSDOM使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSDOM类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: test_serialize
function test_serialize() {
const dom = new JSDOM(`<!DOCTYPE html>hello`);
dom.serialize() === '<!DOCTYPE html><html><head></head><body>hello</body></html>';
// Contrast with:
dom.window.document.documentElement.outerHTML === '<html><head></head><body>hello</body></html>';
}
开发者ID:DanCorder,项目名称:DefinitelyTyped,代码行数:8,代码来源:jsdom-tests.ts
示例2: test_serialize
function test_serialize() {
const dom = new JSDOM(`<!DOCTYPE html>hello`);
dom.serialize() === '<!DOCTYPE html><html><head></head><body>hello</body></html>';
// Contrast with:
// tslint:disable-next-line no-unnecessary-type-assertion
dom.window.document.documentElement!.outerHTML === '<html><head></head><body>hello</body></html>';
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:9,代码来源:jsdom-tests.ts
示例3: test_reconfigure
function test_reconfigure() {
const myFakeTopForTesting = {} as DOMWindow;
const dom = new JSDOM();
dom.window.top === dom.window;
dom.window.location.href === 'about:blank';
dom.reconfigure({ windowTop: myFakeTopForTesting, url: 'https://example.com/' });
dom.window.top === myFakeTopForTesting;
dom.window.location.href === 'https://example.com/';
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:13,代码来源:jsdom-tests.ts
示例4: test_fragment
function test_fragment() {
const frag = JSDOM.fragment(`<p>Hello</p><p><strong>Hi!</strong>`);
frag.childNodes.length === 2;
frag.querySelector('strong')!.textContent = 'Why hello there!';
// etc.
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:7,代码来源:jsdom-tests.ts
示例5: test_fromFile
function test_fromFile() {
const options = {} as FromFileOptions;
JSDOM.fromFile('stuff.html', options).then(dom => {
console.log(dom.serialize());
});
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:7,代码来源:jsdom-tests.ts
示例6: test_fromURL
function test_fromURL() {
const options = {} as FromUrlOptions;
JSDOM.fromURL('https://example.com/', options).then(dom => {
console.log(dom.serialize());
});
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:7,代码来源:jsdom-tests.ts
示例7: test_runVMScript
function test_runVMScript() {
const dom = new JSDOM(``, { runScripts: 'outside-only' });
const s = new Script(`
if (!this.ran) {
this.ran = 0;
}
++this.ran;
`);
dom.runVMScript(s);
dom.runVMScript(s);
dom.runVMScript(s);
(dom.window as any).ran === 3;
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:16,代码来源:jsdom-tests.ts
示例8: function
export default function (html_file) {
return JSDOM.fromFile(html_file).then(dom => {
const external_js = dom.window.document.querySelectorAll('script[type="text/javascript"][src]') as NodeListOf<HTMLScriptElement>;
const inline_js = dom.window.document.querySelectorAll('script[type="text/javascript"]:not([src])');
if (external_js.length === 0) {
return {error: 'No library import'};
}
if (external_js.length > 1) {
return {error: 'Multiple library imports'};
}
if (inline_js.length !== 1) {
return {error: 'No initializer code'};
}
const code_match = inline_js[0].textContent.match(rx_code);
if (!code_match) {
return {error: 'Illegal initializer code'};
}
let init_data;
try {
init_data = json_parse_relax_keys(code_match[1]);
} catch (ex) {
return {error: 'Illegal initializer data'};
}
return {
title: dom.window.document.querySelector("head>title").textContent,
lib: external_js[0].src,
data: init_data
};
});
};
开发者ID:janmarthedal,项目名称:project-dtp,代码行数:30,代码来源:parse-cindy.ts
示例9: test_fragment_serialization
function test_fragment_serialization() {
const frag = JSDOM.fragment(`<p>Hello</p>`);
if (frag instanceof Element) {
if (frag.firstChild instanceof Element) {
console.log(frag.firstChild.outerHTML); // logs "<p>Hello</p>"
}
}
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:8,代码来源:jsdom-tests.ts
示例10:
(resolve, reject) => {
JSDOM.fromFile(entryPageFilePath(issue, uid))
.then((jsdom: JSDOM) => {
resolve(jsdom.window.document);
},
(err) => {
reject(err);
});
}
开发者ID:zenmumbler,项目名称:dtbb,代码行数:9,代码来源:extractor.ts
示例11: test_nodeLocation
function test_nodeLocation() {
const dom = new JSDOM(
`<p>Hello
<img src="foo.jpg">
</p>`,
{ includeNodeLocations: true }
);
const document = dom.window.document;
const bodyEl = document.body; // implicitly created
const pEl = document.querySelector('p')!;
const textNode = pEl.firstChild!;
const imgEl = document.querySelector('img')!;
console.log(dom.nodeLocation(bodyEl)); // null; it's not in the source
console.log(dom.nodeLocation(pEl)); // { startOffset: 0, endOffset: 39, startTag: ..., endTag: ... }
console.log(dom.nodeLocation(textNode)); // { startOffset: 3, endOffset: 13 }
console.log(dom.nodeLocation(imgEl)); // { startOffset: 13, endOffset: 32 }
}
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:19,代码来源:jsdom-tests.ts
示例12: analyzeComicPage
private async analyzeComicPage(url: string): Promise<Comic> {
const ogp = await grabity.grabIt(url),
document = (await JSDOM.fromURL(url)).window.document,
topicMsg = document.getElementById("topics2").textContent;
const comic = {
url,
title: fixchar(ogp.title || ogp["og:title"] || ogp["twitter:title"]).trim(),
thumbnailURL: ogp.image || ogp["og:image"] || ogp["twitter:image:src"],
concluded: (topicMsg.includes("連載は終了しました") || topicMsg.includes("特別読切作品")),
episodes: this.scrapeEpisodes(document),
};
console.info(`MagGarden: Crawled Comic Page - ${comic.title}`);
return comic;
}
开发者ID:phanect,项目名称:ComicAlert,代码行数:16,代码来源:MagGarden.ts
示例13: analyzeMagazinePage
protected async analyzeMagazinePage(
url: string,
name: string,
id: string,
): Promise<Magazine> {
const document = (await JSDOM.fromURL(url)).window.document,
comics: Comic[] = [];
for (const comicBox of Array.from(document.querySelectorAll("article.cbox"))) {
const comicURL = comicBox.querySelector(".inner > a.cbox-main").getAttribute("href");
comics.push(await this.analyzeComicPage(comicURL));
}
this.comics = comics;
console.info("MagGarden: Crawled Magazine Index");
return { id, name, comics };
}
开发者ID:phanect,项目名称:ComicAlert,代码行数:19,代码来源:MagGarden.ts
示例14: fetchIDL
async function fetchIDL(source: IDLSource) {
const response = await fetch(source.url);
if (source.url.endsWith(".idl")) {
return { idl: await response.text() };
}
const dom = JSDOM.fragment(await response.text());
const elements = Array.from(dom.querySelectorAll(idlSelector))
.filter(el => {
if (el.parentElement && el.parentElement.classList.contains("example")) {
return false;
}
const previous = el.previousElementSibling;
if (!previous) {
return true;
}
return !previous.classList.contains("atrisk") && !previous.textContent!.includes("IDL Index");
});
if (!elements.length) {
throw new Error(`Found no IDL code from ${source.url}`);
}
const idl = elements.map(element => trimCommonIndentation(element.textContent!).trim()).join('\n\n');
const comments = processComments(dom);
return { idl, comments };
}
开发者ID:YuichiNukiyama,项目名称:TSJS-lib-generator,代码行数:24,代码来源:fetcher.ts
示例15: fragment
export function fragment(template: string): DocumentFragment {
return JSDOM.fragment(template);
}
开发者ID:milutinovici,项目名称:proactive,代码行数:3,代码来源:spec-utils.ts
示例16: runScript
runScript(script: Script) {
if (this.dom) {
return this.dom.runVMScript(script) as any;
}
return null;
}
开发者ID:facebook,项目名称:jest,代码行数:6,代码来源:index.ts
注:本文中的jsdom.JSDOM类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论