feat(limitTo): ignore limit when undefined #10510
Conversation
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. |
CLAs look good, thanks! |
@@ -15,7 +15,8 @@ | |||
* @param {string|number} limit The length of the returned array or string. If the `limit` number | |||
* is positive, `limit` number of items from the beginning of the source array/string are copied. | |||
* If the number is negative, `limit` number of items from the end of the source array/string | |||
* are copied. The `limit` will be trimmed if it exceeds `array.length` | |||
* are copied. The `limit` will be trimmed if it exceeds `array.length`. If `limit` is undefined, | |||
* the input will be left unchanged. |
gkalpak
Dec 18, 2014
Member
IMO, "returned" is more appropriate than "left" (since the input is left unchanged in any case).
IMO, "returned" is more appropriate than "left" (since the input is left unchanged in any case).
} else { | ||
// zero and NaN check on limit - return empty array | ||
if (!limit) return []; | ||
if (!limit) return input.slice(); |
gkalpak
Dec 18, 2014
Member
This will never evaluate to true
with the current implementation.
This will never evaluate to true
with the current implementation.
expect(limitTo(items, 'null')).toEqual(items); | ||
expect(limitTo(items, 'undefined')).toEqual(items); | ||
expect(limitTo(items, null)).toEqual(items); | ||
expect(limitTo(items, undefined)).toEqual(items); |
gkalpak
Dec 18, 2014
Member
There should also be a test with 0
(to ensure it works as expected).
UPDATE: Has been added.
There should also be a test with 0
(to ensure it works as expected).
UPDATE: Has been added.
expect(limitTo(str, 'null')).toEqual(str); | ||
expect(limitTo(str, 'undefined')).toEqual(str); | ||
expect(limitTo(str, null)).toEqual(str); | ||
expect(limitTo(str, undefined)).toEqual(str); |
gkalpak
Dec 18, 2014
Member
There should also be a test with 0
(to ensure it works as expected).
UPDATE: Has been added.
There should also be a test with 0
(to ensure it works as expected).
UPDATE: Has been added.
I have left a couple of minor comments inline. Additionally, I believe a little refactoring is in place: it would be better (i.e. more maintainable/performant) to do the But "functionality-wise" it should be OK. BTW, the commit message and breaking change notice are slightly inaccurate: It is not only |
@gkalpak thanks for the review |
7d48430
to
f1a6390
I'm lost with the build result. I get:
from job 1. |
expect(limitTo(items, null)).toEqual([]); | ||
expect(limitTo(items, undefined)).toEqual([]); | ||
it('should return an empty array when X = 0', function() { | ||
expect(limitTo(items, 0)).toEqual([]); |
gkalpak
Dec 18, 2014
Member
Nit picking: Could add a test for '0'
(string) as well.
Nit picking: Could add a test for '0'
(string) as well.
}); | ||
|
||
it('should return an empty string when X = 0', function() { | ||
expect(limitTo(str, 0)).toEqual(""); |
gkalpak
Dec 18, 2014
Member
Nit picking: Could add a test for '0'
(string) as well.
(I know it was like this before, but single-quotes would also be preferable to double-quotes for consistency.)
Nit picking: Could add a test for '0'
(string) as well.
(I know it was like this before, but single-quotes would also be preferable to double-quotes for consistency.)
marcin-wosinek
Dec 18, 2014
Author
Contributor
Added
Added
@marcin-wosinek: It is a flake (not related to the build) on SauseLabs only. I restarted the job, but since the tests passed on BrowserStack, it should be OK. I left two "nit-picky" comments on the tests, but other than that it looks good to me. (There's a typo in the BREAKING CHANGE notice btw: |
d2e50bd
to
b66a1fe
LGTM |
BREAKING CHANGE: limitTo changed behavior when limit value is invalid. Instead of returning empty object/array it returns unchanged input. Closes #10484
BREAKING CHANGE: limitTo changed behavoir when limit value is undefined.
Instead of returning empty object/array it returns non-changed input.
Closes #10484