diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 2e776517..61f389d1 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -970,13 +970,26 @@ jasmineRequire.ResultsNode = function() { }; jasmineRequire.QueryString = function() { + /** + * Reads and manipulates the query string. + * @since 2.0.0 + */ class QueryString { #getWindowLocation; + /** + * @param options Object with a getWindowLocation property, which should be + * a function returning the current value of window.location. + */ constructor(options) { this.#getWindowLocation = options.getWindowLocation; } + /** + * Sets the specified query parameter and navigates to the resulting URL. + * @param {string} key + * @param {string} value + */ navigateWithNewParam(key, value) { this.#getWindowLocation().search = this.fullStringWithNewParam( key, @@ -984,12 +997,24 @@ jasmineRequire.QueryString = function() { ); } + /** + * Returns a new URL based on the current location, with the specified + * query parameter set. + * @param {string} key + * @param {string} value + * @return {string} + */ fullStringWithNewParam(key, value) { const paramMap = this.#queryStringToParamMap(); paramMap[key] = value; return toQueryString(paramMap); } + /** + * Gets the value of the specified query parameter. + * @param {string} key + * @return {string} + */ getParam(key) { return this.#queryStringToParamMap()[key]; } diff --git a/src/html/QueryString.js b/src/html/QueryString.js index 8ed5bc62..f82a4dd0 100644 --- a/src/html/QueryString.js +++ b/src/html/QueryString.js @@ -1,11 +1,24 @@ jasmineRequire.QueryString = function() { + /** + * Reads and manipulates the query string. + * @since 2.0.0 + */ class QueryString { #getWindowLocation; + /** + * @param options Object with a getWindowLocation property, which should be + * a function returning the current value of window.location. + */ constructor(options) { this.#getWindowLocation = options.getWindowLocation; } + /** + * Sets the specified query parameter and navigates to the resulting URL. + * @param {string} key + * @param {string} value + */ navigateWithNewParam(key, value) { this.#getWindowLocation().search = this.fullStringWithNewParam( key, @@ -13,12 +26,24 @@ jasmineRequire.QueryString = function() { ); } + /** + * Returns a new URL based on the current location, with the specified + * query parameter set. + * @param {string} key + * @param {string} value + * @return {string} + */ fullStringWithNewParam(key, value) { const paramMap = this.#queryStringToParamMap(); paramMap[key] = value; return toQueryString(paramMap); } + /** + * Gets the value of the specified query parameter. + * @param {string} key + * @return {string} + */ getParam(key) { return this.#queryStringToParamMap()[key]; }