DefinitelyTyped/types/html-parser/html-parser-tests.ts
Max Boguslavsky 3779419226 Added type for html-parser (#38940)
* - added draft type for html-parser

* fixed dom reference in package; corrected options interface; rewrote tests

* reverted prev commit

* corrected options interface; introduced dom lib into global space; corrected tests params

* reverted prev commit

* - added some tests.

* added @type/html-parses

* corrected formatting

* corrected formatting

* corrected errors after namespace correction

* removed namespace declaration

* corrected export declarations

* fixed comments

* corrected formatting

* rewrote args so that they will be self-explanatory

* corrected formatting
2019-10-09 11:02:22 -07:00

45 lines
1.4 KiB
TypeScript

import { parse, parseFile, sanitize, RegExpOptions, CallbacksOption, Token } from 'html-parser';
// test data
const attributes = (arg: string) => arg;
const elements = (arg: string) => arg;
const comments = (arg: boolean) => arg;
const docTypes = (arg: boolean) => arg;
const attribute = (name: string, value: string) => {};
const openElement = (tagName: string) => {};
const closeOpenedElement = (tagName: string, token: Token, isUnary: boolean) => {};
const closeElement = (name: string) => {};
const comment = (content: string) => {};
const docType = (content: string) => {};
const cdata = (content: string) => {};
const xmlProlog = () => {};
const text = (value: string) => {};
const emptyRegExpOptions: RegExpOptions = {};
const filledRegExpOptions: RegExpOptions = {attribute: new RegExp(''), name: new RegExp('')};
const emptyCallbackOptions: CallbacksOption = {};
const filled: CallbacksOption = {
attribute,
openElement,
closeOpenedElement,
closeElement,
comment,
docType,
cdata,
xmlProlog,
text
};
// parse tests:
parse('');
parse('', emptyCallbackOptions, emptyRegExpOptions);
parse('', filled, filledRegExpOptions);
// parseFile tests:
parseFile('', '', emptyCallbackOptions, attributes);
parseFile('', '', filled, attributes);
// sanitize tests:
sanitize('');
sanitize('', {attributes: [ 'hello' ], elements: [ 'hi' ], comments: true, docTypes: false});
sanitize('', {attributes, elements, comments, docTypes });