faker icon indicating copy to clipboard operation
faker copied to clipboard

feat(helpers): allow using parameters in `method` param of `multiple`

Open pomali opened this issue 2 years ago • 4 comments

faker.helpers.multiple() supports using mapFn like in Array.from(), but type signature of function didn't match, PR fixes this and adds test for this case

(but since it changes declared interface I chose feat instead of fix as semantic type)

pomali avatar Nov 30 '23 10:11 pomali

I'm not sure if this fits the use case of faker.helpers.multiple :thinking:

If you require the parameters of the mal function, you are most likely doing some static value generation.

I need some time to think about this in more detail.

xDivisionByZerox avatar Nov 30 '23 10:11 xDivisionByZerox

Yes, usecase here is generating two sets of objects with matching ids, so I can "join" them later. Eg.

interface School { locationId: number }
interface Location { id: number }

I could create an function with no arguments that simulates this behavior, but it seemed busywork since underlying code already supports it.

I am using it in place without shared state (in mock service worker in two different endpoints)

pomali avatar Nov 30 '23 11:11 pomali

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 99.56%. Comparing base (9348138) to head (529aac6).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2563      +/-   ##
==========================================
- Coverage   99.57%   99.56%   -0.02%     
==========================================
  Files        2846     2846              
  Lines      248715   248717       +2     
  Branches      655     1011     +356     
==========================================
- Hits       247669   247634      -35     
- Misses       1017     1083      +66     
+ Partials       29        0      -29     
Files Coverage Δ
src/modules/helpers/index.ts 98.82% <100.00%> (+<0.01%) :arrow_up:

... and 30 files with indirect coverage changes

codecov[bot] avatar Nov 30 '23 12:11 codecov[bot]

Sorry for the delay in feedback. Could you please update this PR with the latest suggestions?

ST-DDT avatar Feb 15 '24 16:02 ST-DDT

Sorry for the delay in feedback. Could you please update this PR with the latest suggestions?

No problem, sorry for mine delay. Updated.

pomali avatar Feb 20 '24 17:02 pomali

Could you please fix the broken tests and examples? The tests were already broken due to the wrong typing of the method before, but now the method actually requires proper types and thus the bad usage actually shows up.

firstName -> () -> firstName()

ST-DDT avatar Feb 21 '24 08:02 ST-DDT

Please also enable allow edits by maintainers on this PR so we can update it ourself to the latest commits on next.

ST-DDT avatar Feb 21 '24 08:02 ST-DDT

Do we consider this breaking?

Because previously you could incorrectly pass any function reference directly to the method even, if it would be called with garbage values, so it is kind of a bugfix, but one that prevents you from doing bad things.

ST-DDT avatar Mar 01 '24 22:03 ST-DDT

Do we consider this breaking?

I think it's better to mark it as breaking as not doing it and then it was breaking

Shinigami92 avatar Mar 01 '24 23:03 Shinigami92