![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
cypress-map
Advanced tools
Extra Cypress query commands for v12+
Add this package as a dev dependency
$ npm i -D cypress-map
# or using Yarn
$ yarn add -D cypress-map
Include this package in your spec or support file to use all custom query commands
import 'cypress-map'
Alternative: import only the query commands you need:
import 'cypress-map/commands/map'
import 'cypress-map/commands/tap'
// and so on, see the /commands folder
const double = (n) => n * 2
cy.wrap(100).apply(double).should('equal', 200)
cy.get('.matching')
.map('innerText')
.should('deep.equal', ['first', 'third', 'fourth'])
cy.get('#items li')
.find('.price')
.map('innerText')
.mapInvoke('replace', '$', '')
.mapInvoke('trim')
cy.get('#items li')
.find('.price')
.map('innerText')
.mapInvoke('replace', '$', '')
.map(parseFloat)
.reduce((max, n) => (n > max ? n : max))
// yields the highest price
You can provide the initial accumulator value
cy.wrap([1, 2, 3])
.reduce((sum, n) => sum + n, 10)
.should('equal', 16)
See reduce.cy.js
cy.get('#items li')
.find('.price')
.map('innerText')
.tap() // console.log by default
.mapInvoke('replace', '$', '')
.mapInvoke('trim')
// console.info with extra label
.tap(console.info, 'trimmed strings')
Notice: if the label is provided, the callback function is called with label and the subject.
A better cy.log
: yields the value, intelligently stringifies values using %
and string-format notation.
cy.wrap(42)
.print() // "42"
// and yields the value
.should('equal', 42)
// pass formatting string
cy.wrap(42).print('the answer is %d') // "the answer is 42"
cy.wrap({ name: 'Joe' }).print('person %o') // 'person {"name":"Joe"}'
// use {0} with dot notation, supported deep properties
// https://github.com/davidchambers/string-format
cy.wrap({ name: 'Joe' }).print('person name {0.name}') // "person name Joe"
// print the length of an array
cy.wrap(arr).print('array length {0.length}') // "array length ..."
// pass your own function to return formatted string
cy.wrap(arr).print((a) => `array with ${a.length} items`)
// if you return a non-string, it will attempt to JSON.stringify it
cy.wrap(arr).print((list) => list[2]) // JSON.stringify(arr[2])
See print.cy.js for more examples
cy.get('.matching')
.map('innerText')
.primo()
.invoke('toUpperCase')
.should('equal', 'FIRST')
See primo.cy.js
Works like cy.its
for objects, but gets the property for jQuery objects, which cy.its
does not
cy.get('#items li.matching').last().prop('ariaLabel').should('equal', 'four')
See prop.cy.js
Returns a DOM element from jQuery object at position k
. Returns an item from array at position k
. For negative index, counts the items from the end.
cy.get('#items li').at(-1).its('innerText').should('equal', 'fifth')
See at.cy.js
Here are a few examples to clarify the different between the cy.invoke
, cy.map
, and cy.mapInvoke
query commands, see diff.cy.js
const list = ['apples', 'plums', 'bananas']
// cy.invoke
cy.wrap(list)
// calls ".sort()" on the list
.invoke('sort')
.should('deep.equal', ['apples', 'bananas', 'plums'])
// cy.mapInvoke
cy.wrap(list)
// calls ".toUpperCase()" on every string in the list
.mapInvoke('toUpperCase')
.should('deep.equal', ['APPLES', 'PLUMS', 'BANANAS'])
// cy.map
const reverse = (s) => s.split('').reverse().join('')
cy.wrap(list)
// reverses each string in the list
.map(reverse)
.should('deep.equal', ['selppa', 'smulp', 'sananab'])
// grabs the "length" property from each string
.map('length')
.should('deep.equal', [6, 5, 7])
should(callback)
function on the fly.Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022
License: MIT - do anything with the code, but don't blame me if it does not work.
Support: if you find any problems with this module, email / tweet / open issue on Github
FAQs
Extra Cypress query commands for v12+
The npm package cypress-map receives a total of 28,222 weekly downloads. As such, cypress-map popularity was classified as popular.
We found that cypress-map demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.