Uploaded February 2025 | Updated September 2026, 1 week ago
The simplest end-to-end Cypress tests are tests that control the data and remove all randomness. In this video, I show how to stub the "Math.random" method the application calls to get random item ids. By stubbing this method, the test forces the application to always create items with the same deterministic id. Checking if that item is shown in the DOM becomes declarative command, without any need for "cy.then" or aliases. Find the source code in the pull request github.com/bahmutov/todomvc-callback-example/pull/4
The simplest end-to-end Cypress tests are tests that control the data and remove all randomness. In this video, I show how to stub the "Math.random" method the application calls to get random item ids. By stubbing this method, the test forces the application to always create items with the same deterministic id. Checking if that item is shown in the DOM becomes declarative command, without any need for "cy.then" or aliases. Find the source code in the pull request github.com/bahmutov/todomvc-callback-example/pull/4




![Remove Numbers From Strings
This video shows how to take multiple elements, remove numbers from each text, trim those strings, and confirm them.
cy.get(#fruit li) // jQuery Element[]
.map(innerText) // string[]
.mapInvoke(replace, /[ds]/g, ) // string[]
.should(deep.equal, [Apples, Grapes, Kiwi])
The retryable query commands cy.map and cy.mapInvoke come from my plugin https://github.com/bahmutov/cypress-map The full example is at https://glebbahmutov.com/cypress-examples Remove Numbers From Strings](https://i.ytimg.com/vi/OXiEJDjozQo/mqdefault.jpg)





