cypress-each
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "cypress-each", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Simple implementation for describe.each and it.each", | ||
@@ -5,0 +5,0 @@ "main": "src", |
@@ -12,1 +12,42 @@ # cypress-each ![cypress version](https://img.shields.io/badge/cypress-8.5.0-brightgreen) | ||
- [mocha-each-spec.js](cypress/integration/mocha-each-spec.js) uses 3rd party [mocha-each](https://github.com/ryym/mocha-each) to generate `it` tests for each data item | ||
## Small print | ||
Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2021 | ||
- [@bahmutov](https://twitter.com/bahmutov) | ||
- [glebbahmutov.com](https://glebbahmutov.com) | ||
- [blog](https://glebbahmutov.com/blog) | ||
- [videos](https://www.youtube.com/glebbahmutov) | ||
- [presentations](https://slides.com/bahmutov) | ||
- [cypress.tips](https://cypress.tips) | ||
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](https://github.com/bahmutov/cypress-each/issues) on Github | ||
## MIT License | ||
Copyright (c) 2021 Gleb Bahmutov <gleb.bahmutov@gmail.com> | ||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
@@ -6,2 +6,9 @@ /// <reference types="cypress" /> | ||
function formatTitle(pattern, ...values) { | ||
// count how many format placeholders are in the pattern | ||
// by counting the "%" characters | ||
const count = pattern.match(/%/g).length | ||
return format.apply(null, [pattern].concat(values.slice(0, count))) | ||
} | ||
if (!it.each) { | ||
@@ -13,6 +20,6 @@ it.each = (values) => { | ||
if (Array.isArray(value)) { | ||
const title = format(titlePattern, ...value) | ||
const title = formatTitle(titlePattern, ...value) | ||
it(title, testCallback.bind(null, ...value)) | ||
} else { | ||
const title = format(titlePattern, value) | ||
const title = formatTitle(titlePattern, value) | ||
it(title, testCallback.bind(null, value)) | ||
@@ -31,6 +38,6 @@ } | ||
if (Array.isArray(value)) { | ||
const title = format(titlePattern, ...value) | ||
const title = formatTitle(titlePattern, ...value) | ||
describe(title, testCallback.bind(null, ...value)) | ||
} else { | ||
const title = format(titlePattern, value) | ||
const title = formatTitle(titlePattern, value) | ||
describe(title, testCallback.bind(null, value)) | ||
@@ -37,0 +44,0 @@ } |
4534
41
53