cypress-map
Advanced tools
Comparing version 1.29.0 to 1.30.0
var registerQuery = require('./utils').registerQuery; | ||
registerQuery('toPlainObject', function () { | ||
var log = Cypress.log({ name: 'toPlainObject' }); | ||
return function (subject) { | ||
registerQuery('toPlainObject', function (conversionType) { | ||
if (conversionType === void 0) { conversionType = 'json'; } | ||
var log = Cypress.log({ | ||
name: 'toPlainObject', | ||
message: conversionType, | ||
}); | ||
var jsonConversion = function (subject) { | ||
return JSON.parse(JSON.stringify(subject)); | ||
}; | ||
var entriesConversion = function (subject) { | ||
return Object.fromEntries(subject.entries()); | ||
}; | ||
if (conversionType === 'json') { | ||
return jsonConversion; | ||
} | ||
else if (conversionType === 'entries') { | ||
return entriesConversion; | ||
} | ||
else { | ||
throw new Error("unknown conversion type: ".concat(conversionType)); | ||
} | ||
}); |
{ | ||
"name": "cypress-map", | ||
"version": "1.29.0", | ||
"version": "1.30.0", | ||
"description": "Extra Cypress query commands for v12+", | ||
@@ -5,0 +5,0 @@ "main": "commands/index.js", |
@@ -468,2 +468,8 @@ # cypress-map [![ci](https://github.com/bahmutov/cypress-map/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/bahmutov/cypress-map/actions/workflows/ci.yml) ![cypress version](https://img.shields.io/badge/cypress-13.6.4-brightgreen) | ||
By default uses JSON stringify and parse back. If you want to convert using `entries` and `fromEntries`, add an argument: | ||
```js | ||
cy.wrap(new URLSearchParams(searchParams)).toPlainObject('entries') | ||
``` | ||
### invokeOnce | ||
@@ -470,0 +476,0 @@ |
@@ -240,4 +240,7 @@ /** | ||
/** | ||
* A query that calls `JSON.parse(JSON.parse(subject))` | ||
* A query that calls `JSON.parse(JSON.parse(subject))` or entries. | ||
* When using `entries`, it calls `Object.entries` | ||
* then constructs the object again using `Object.fromEntries`. | ||
* @see https://github.com/bahmutov/cypress-map | ||
* @param conversionType Json by default, could be 'entries' | ||
* @example | ||
@@ -250,3 +253,5 @@ * cy.get('selector') | ||
*/ | ||
toPlainObject(): Chainable<Object> | ||
toPlainObject( | ||
conversionType?: 'json' | 'entries', | ||
): Chainable<Object> | ||
@@ -253,0 +258,0 @@ /** |
59277
1041
578