Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. <div align="center">
  2. <h1>jest-each</h1>
  3. Jest Parameterised Testing
  4. </div>
  5. <hr />
  6. [![version](https://img.shields.io/npm/v/jest-each.svg?style=flat-square)](https://www.npmjs.com/package/jest-each) [![downloads](https://img.shields.io/npm/dm/jest-each.svg?style=flat-square)](http://npm-stat.com/charts.html?package=jest-each&from=2017-03-21) [![MIT License](https://img.shields.io/npm/l/jest-each.svg?style=flat-square)](https://github.com/facebook/jest/blob/main/LICENSE)
  7. A parameterised testing library for [Jest](https://jestjs.io/) inspired by [mocha-each](https://github.com/ryym/mocha-each).
  8. jest-each allows you to provide multiple arguments to your `test`/`describe` which results in the test/suite being run once per row of parameters.
  9. ## Features
  10. - `.test` to runs multiple tests with parameterised data
  11. - Also under the alias: `.it`
  12. - `.test.only` to only run the parameterised tests
  13. - Also under the aliases: `.it.only` or `.fit`
  14. - `.test.skip` to skip the parameterised tests
  15. - Also under the aliases: `.it.skip` or `.xit` or `.xtest`
  16. - `.test.concurrent`
  17. - Also under the alias: `.it.concurrent`
  18. - `.test.concurrent.only`
  19. - Also under the alias: `.it.concurrent.only`
  20. - `.test.concurrent.skip`
  21. - Also under the alias: `.it.concurrent.skip`
  22. - `.describe` to runs test suites with parameterised data
  23. - `.describe.only` to only run the parameterised suite of tests
  24. - Also under the aliases: `.fdescribe`
  25. - `.describe.skip` to skip the parameterised suite of tests
  26. - Also under the aliases: `.xdescribe`
  27. - Asynchronous tests with `done`
  28. - Unique test titles with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
  29. - `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
  30. - `%s`- String.
  31. - `%d`- Number.
  32. - `%i` - Integer.
  33. - `%f` - Floating point value.
  34. - `%j` - JSON.
  35. - `%o` - Object.
  36. - `%#` - Index of the test case.
  37. - `%%` - single percent sign ('%'). This does not consume an argument.
  38. - Unique test titles by injecting properties of test case object
  39. - 🖖 Spock like data tables with [Tagged Template Literals](#tagged-template-literal-of-rows)
  40. ---
  41. - [Demo](#demo)
  42. - [Installation](#installation)
  43. - [Importing](#importing)
  44. - APIs
  45. - [Array of Rows](#array-of-rows)
  46. - [Usage](#usage)
  47. - [Tagged Template Literal of rows](#tagged-template-literal-of-rows)
  48. - [Usage](#usage-1)
  49. ## Demo
  50. #### Tests without jest-each
  51. ![Current jest tests](assets/default-demo.gif)
  52. #### Tests can be re-written with jest-each to:
  53. **`.test`**
  54. ![Current jest tests](assets/test-demo.gif)
  55. **`.test` with Tagged Template Literals**
  56. ![Current jest tests](assets/tagged-template-literal.gif)
  57. **`.describe`**
  58. ![Current jest tests](assets/describe-demo.gif)
  59. ## Installation
  60. `npm i --save-dev jest-each`
  61. `yarn add -D jest-each`
  62. ## Importing
  63. jest-each is a default export so it can be imported with whatever name you like.
  64. ```js
  65. // es6
  66. import each from 'jest-each';
  67. ```
  68. ```js
  69. // es5
  70. const each = require('jest-each').default;
  71. ```
  72. ## Array of rows
  73. ### API
  74. #### `each([parameters]).test(name, testFn)`
  75. ##### `each`:
  76. - parameters: `Array` of Arrays with the arguments that are passed into the `testFn` for each row
  77. - _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
  78. ##### `.test`:
  79. - name: `String` the title of the `test`.
  80. - Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
  81. - `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
  82. - `%s`- String.
  83. - `%d`- Number.
  84. - `%i` - Integer.
  85. - `%f` - Floating point value.
  86. - `%j` - JSON.
  87. - `%o` - Object.
  88. - `%#` - Index of the test case.
  89. - `%%` - single percent sign ('%'). This does not consume an argument.
  90. - Or generate unique test titles by injecting properties of test case object with `$variable`
  91. - To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
  92. - You can use `$#` to inject the index of the test case
  93. - You cannot use `$variable` with the `printf` formatting except for `%%`
  94. - testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments
  95. #### `each([parameters]).describe(name, suiteFn)`
  96. ##### `each`:
  97. - parameters: `Array` of Arrays with the arguments that are passed into the `suiteFn` for each row
  98. - _Note_ If you pass in a 1D array of primitives, internally it will be mapped to a table i.e. `[1, 2, 3] -> [[1], [2], [3]]`
  99. ##### `.describe`:
  100. - name: `String` the title of the `describe`
  101. - Generate unique test titles by positionally injecting parameters with [`printf` formatting](https://nodejs.org/api/util.html#util_util_format_format_args):
  102. - `%p` - [pretty-format](https://www.npmjs.com/package/pretty-format).
  103. - `%s`- String.
  104. - `%d`- Number.
  105. - `%i` - Integer.
  106. - `%f` - Floating point value.
  107. - `%j` - JSON.
  108. - `%o` - Object.
  109. - `%#` - Index of the test case.
  110. - `%%` - single percent sign ('%'). This does not consume an argument.
  111. - Or generate unique test titles by injecting properties of test case object with `$variable`
  112. - To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
  113. - You can use `$#` to inject the index of the test case
  114. - You cannot use `$variable` with the `printf` formatting except for `%%`
  115. - suiteFn: `Function` the suite of `test`/`it`s to be ran, this is the function that will receive the parameters in each row as function arguments
  116. ### Usage
  117. #### `.test(name, fn)`
  118. Alias: `.it(name, fn)`
  119. ```js
  120. each([
  121. [1, 1, 2],
  122. [1, 2, 3],
  123. [2, 1, 3],
  124. ]).test('returns the result of adding %d to %d', (a, b, expected) => {
  125. expect(a + b).toBe(expected);
  126. });
  127. ```
  128. ```js
  129. each([
  130. {a: 1, b: 1, expected: 2},
  131. {a: 1, b: 2, expected: 3},
  132. {a: 2, b: 1, expected: 3},
  133. ]).test('returns the result of adding $a to $b', ({a, b, expected}) => {
  134. expect(a + b).toBe(expected);
  135. });
  136. ```
  137. #### `.test.only(name, fn)`
  138. Aliases: `.it.only(name, fn)` or `.fit(name, fn)`
  139. ```js
  140. each([
  141. [1, 1, 2],
  142. [1, 2, 3],
  143. [2, 1, 3],
  144. ]).test.only('returns the result of adding %d to %d', (a, b, expected) => {
  145. expect(a + b).toBe(expected);
  146. });
  147. ```
  148. #### `.test.skip(name, fn)`
  149. Aliases: `.it.skip(name, fn)` or `.xit(name, fn)` or `.xtest(name, fn)`
  150. ```js
  151. each([
  152. [1, 1, 2],
  153. [1, 2, 3],
  154. [2, 1, 3],
  155. ]).test.skip('returns the result of adding %d to %d', (a, b, expected) => {
  156. expect(a + b).toBe(expected);
  157. });
  158. ```
  159. #### `.test.concurrent(name, fn)`
  160. Aliases: `.it.concurrent(name, fn)`
  161. ```js
  162. each([
  163. [1, 1, 2],
  164. [1, 2, 3],
  165. [2, 1, 3],
  166. ]).test.concurrent(
  167. 'returns the result of adding %d to %d',
  168. (a, b, expected) => {
  169. expect(a + b).toBe(expected);
  170. },
  171. );
  172. ```
  173. #### `.test.concurrent.only(name, fn)`
  174. Aliases: `.it.concurrent.only(name, fn)`
  175. ```js
  176. each([
  177. [1, 1, 2],
  178. [1, 2, 3],
  179. [2, 1, 3],
  180. ]).test.concurrent.only(
  181. 'returns the result of adding %d to %d',
  182. (a, b, expected) => {
  183. expect(a + b).toBe(expected);
  184. },
  185. );
  186. ```
  187. #### `.test.concurrent.skip(name, fn)`
  188. Aliases: `.it.concurrent.skip(name, fn)`
  189. ```js
  190. each([
  191. [1, 1, 2],
  192. [1, 2, 3],
  193. [2, 1, 3],
  194. ]).test.concurrent.skip(
  195. 'returns the result of adding %d to %d',
  196. (a, b, expected) => {
  197. expect(a + b).toBe(expected);
  198. },
  199. );
  200. ```
  201. #### Asynchronous `.test(name, fn(done))`
  202. Alias: `.it(name, fn(done))`
  203. ```js
  204. each([['hello'], ['mr'], ['spy']]).test(
  205. 'gives 007 secret message: %s',
  206. (str, done) => {
  207. const asynchronousSpy = message => {
  208. expect(message).toBe(str);
  209. done();
  210. };
  211. callSomeAsynchronousFunction(asynchronousSpy)(str);
  212. },
  213. );
  214. ```
  215. #### `.describe(name, fn)`
  216. ```js
  217. each([
  218. [1, 1, 2],
  219. [1, 2, 3],
  220. [2, 1, 3],
  221. ]).describe('.add(%d, %d)', (a, b, expected) => {
  222. test(`returns ${expected}`, () => {
  223. expect(a + b).toBe(expected);
  224. });
  225. test('does not mutate first arg', () => {
  226. a + b;
  227. expect(a).toBe(a);
  228. });
  229. test('does not mutate second arg', () => {
  230. a + b;
  231. expect(b).toBe(b);
  232. });
  233. });
  234. ```
  235. ```js
  236. each([
  237. {a: 1, b: 1, expected: 2},
  238. {a: 1, b: 2, expected: 3},
  239. {a: 2, b: 1, expected: 3},
  240. ]).describe('.add($a, $b)', ({a, b, expected}) => {
  241. test(`returns ${expected}`, () => {
  242. expect(a + b).toBe(expected);
  243. });
  244. test('does not mutate first arg', () => {
  245. a + b;
  246. expect(a).toBe(a);
  247. });
  248. test('does not mutate second arg', () => {
  249. a + b;
  250. expect(b).toBe(b);
  251. });
  252. });
  253. ```
  254. #### `.describe.only(name, fn)`
  255. Aliases: `.fdescribe(name, fn)`
  256. ```js
  257. each([
  258. [1, 1, 2],
  259. [1, 2, 3],
  260. [2, 1, 3],
  261. ]).describe.only('.add(%d, %d)', (a, b, expected) => {
  262. test(`returns ${expected}`, () => {
  263. expect(a + b).toBe(expected);
  264. });
  265. });
  266. ```
  267. #### `.describe.skip(name, fn)`
  268. Aliases: `.xdescribe(name, fn)`
  269. ```js
  270. each([
  271. [1, 1, 2],
  272. [1, 2, 3],
  273. [2, 1, 3],
  274. ]).describe.skip('.add(%d, %d)', (a, b, expected) => {
  275. test(`returns ${expected}`, () => {
  276. expect(a + b).toBe(expected);
  277. });
  278. });
  279. ```
  280. ---
  281. ## Tagged Template Literal of rows
  282. ### API
  283. #### `each[tagged template].test(name, suiteFn)`
  284. ```js
  285. each`
  286. a | b | expected
  287. ${1} | ${1} | ${2}
  288. ${1} | ${2} | ${3}
  289. ${2} | ${1} | ${3}
  290. `.test('returns $expected when adding $a to $b', ({a, b, expected}) => {
  291. expect(a + b).toBe(expected);
  292. });
  293. ```
  294. ##### `each` takes a tagged template string with:
  295. - First row of variable name column headings separated with `|`
  296. - One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
  297. ##### `.test`:
  298. - name: `String` the title of the `test`, use `$variable` in the name string to inject test values into the test title from the tagged template expressions
  299. - To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
  300. - You can use `$#` to inject the index of the table row.
  301. - testFn: `Function` the test logic, this is the function that will receive the parameters of each row as function arguments
  302. #### `each[tagged template].describe(name, suiteFn)`
  303. ```js
  304. each`
  305. a | b | expected
  306. ${1} | ${1} | ${2}
  307. ${1} | ${2} | ${3}
  308. ${2} | ${1} | ${3}
  309. `.describe('$a + $b', ({a, b, expected}) => {
  310. test(`returns ${expected}`, () => {
  311. expect(a + b).toBe(expected);
  312. });
  313. test('does not mutate first arg', () => {
  314. a + b;
  315. expect(a).toBe(a);
  316. });
  317. test('does not mutate second arg', () => {
  318. a + b;
  319. expect(b).toBe(b);
  320. });
  321. });
  322. ```
  323. ##### `each` takes a tagged template string with:
  324. - First row of variable name column headings separated with `|`
  325. - One or more subsequent rows of data supplied as template literal expressions using `${value}` syntax.
  326. ##### `.describe`:
  327. - name: `String` the title of the `test`, use `$variable` in the name string to inject test values into the test title from the tagged template expressions
  328. - To inject nested object values use you can supply a keyPath i.e. `$variable.path.to.value`
  329. - suiteFn: `Function` the suite of `test`/`it`s to be ran, this is the function that will receive the parameters in each row as function arguments
  330. ### Usage
  331. #### `.test(name, fn)`
  332. Alias: `.it(name, fn)`
  333. ```js
  334. each`
  335. a | b | expected
  336. ${1} | ${1} | ${2}
  337. ${1} | ${2} | ${3}
  338. ${2} | ${1} | ${3}
  339. `.test('returns $expected when adding $a to $b', ({a, b, expected}) => {
  340. expect(a + b).toBe(expected);
  341. });
  342. ```
  343. #### `.test.only(name, fn)`
  344. Aliases: `.it.only(name, fn)` or `.fit(name, fn)`
  345. ```js
  346. each`
  347. a | b | expected
  348. ${1} | ${1} | ${2}
  349. ${1} | ${2} | ${3}
  350. ${2} | ${1} | ${3}
  351. `.test.only('returns $expected when adding $a to $b', ({a, b, expected}) => {
  352. expect(a + b).toBe(expected);
  353. });
  354. ```
  355. #### `.test.skip(name, fn)`
  356. Aliases: `.it.skip(name, fn)` or `.xit(name, fn)` or `.xtest(name, fn)`
  357. ```js
  358. each`
  359. a | b | expected
  360. ${1} | ${1} | ${2}
  361. ${1} | ${2} | ${3}
  362. ${2} | ${1} | ${3}
  363. `.test.skip('returns $expected when adding $a to $b', ({a, b, expected}) => {
  364. expect(a + b).toBe(expected);
  365. });
  366. ```
  367. #### Asynchronous `.test(name, fn(done))`
  368. Alias: `.it(name, fn(done))`
  369. ```js
  370. each`
  371. str
  372. ${'hello'}
  373. ${'mr'}
  374. ${'spy'}
  375. `.test('gives 007 secret message: $str', ({str}, done) => {
  376. const asynchronousSpy = message => {
  377. expect(message).toBe(str);
  378. done();
  379. };
  380. callSomeAsynchronousFunction(asynchronousSpy)(str);
  381. });
  382. ```
  383. #### `.describe(name, fn)`
  384. ```js
  385. each`
  386. a | b | expected
  387. ${1} | ${1} | ${2}
  388. ${1} | ${2} | ${3}
  389. ${2} | ${1} | ${3}
  390. `.describe('$a + $b', ({a, b, expected}) => {
  391. test(`returns ${expected}`, () => {
  392. expect(a + b).toBe(expected);
  393. });
  394. test('does not mutate first arg', () => {
  395. a + b;
  396. expect(a).toBe(a);
  397. });
  398. test('does not mutate second arg', () => {
  399. a + b;
  400. expect(b).toBe(b);
  401. });
  402. });
  403. ```
  404. #### `.describe.only(name, fn)`
  405. Aliases: `.fdescribe(name, fn)`
  406. ```js
  407. each`
  408. a | b | expected
  409. ${1} | ${1} | ${2}
  410. ${1} | ${2} | ${3}
  411. ${2} | ${1} | ${3}
  412. `.describe.only('$a + $b', ({a, b, expected}) => {
  413. test(`returns ${expected}`, () => {
  414. expect(a + b).toBe(expected);
  415. });
  416. });
  417. ```
  418. #### `.describe.skip(name, fn)`
  419. Aliases: `.xdescribe(name, fn)`
  420. ```js
  421. each`
  422. a | b | expected
  423. ${1} | ${1} | ${2}
  424. ${1} | ${2} | ${3}
  425. ${2} | ${1} | ${3}
  426. `.describe.skip('$a + $b', ({a, b, expected}) => {
  427. test(`returns ${expected}`, () => {
  428. expect(a + b).toBe(expected);
  429. });
  430. });
  431. ```
  432. ## License
  433. MIT