-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Rename createParser to configureTestParser
- module name kebab case - document it's usefulness and parameters
- Loading branch information
Showing
4 changed files
with
42 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var {DOMParser} = require('../lib/dom-parser') | ||
|
||
/** | ||
* @typedef ErrorLevel {'warn' | 'error' | 'fatal'} | ||
*/ | ||
/** | ||
* Helper method for configuring an instance of DOMParser. | ||
* Calling it without any arguments allows to assert on `errors` after using the parser. | ||
* every field of the first argument is options and allows to specify test specific behavior. | ||
* - `errorHandler`: The `locator` to pass to DOMParser constructor options, | ||
* default stores a list of all entries per `key` in `errors` and does not log or throw. | ||
* - `errors`: the object for the `errorHandler` to use, | ||
* is also returned with the same name for later assertions, | ||
* default is an empty object | ||
* - `locator`: The `locator` to pass to DOMParser constructor options, | ||
* default is an empty object | ||
* | ||
* @param options {{ | ||
* errorHandler?: function (key: ErrorLevel, msg: string), | ||
* errors?: Partial<Record<ErrorLevel, string[]>>, | ||
* locator?: Object | ||
* }} | ||
* @returns {{parser: DOMParser, errors: Partial<Record<ErrorLevel, string[]>>}} | ||
*/ | ||
function configureTestParser ({errorHandler, errors = {}, locator = {}} = {}) { | ||
errorHandler = errorHandler || ((key, msg) => { | ||
if (!errors[key]) errors[key] = [] | ||
errors[key].push(msg) | ||
}) | ||
return { | ||
errors, | ||
parser: new DOMParser({errorHandler, locator}) | ||
} | ||
} | ||
|
||
module.exports = { | ||
configureTestParser | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters