-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dependabot/npm_and_yarn/semver-5.7.2
- Loading branch information
Showing
5 changed files
with
136 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { addToTotalIfNumber } from '../addToTotalIfNumber.js' | ||
|
||
const tests = [ | ||
{ | ||
testName: 'negative value', | ||
value: -1, | ||
total: undefined, | ||
expected: -1, | ||
}, | ||
{ | ||
testName: 'zero value', | ||
value: 0, | ||
total: undefined, | ||
expected: 0, | ||
}, | ||
{ | ||
testName: 'positive value', | ||
value: 1, | ||
total: undefined, | ||
expected: 1, | ||
}, | ||
{ | ||
testName: 'null value', | ||
value: null, | ||
total: undefined, | ||
expected: undefined, | ||
}, | ||
{ | ||
testName: 'undefined value', | ||
value: undefined, | ||
total: undefined, | ||
expected: undefined, | ||
}, | ||
{ | ||
testName: 'string value', | ||
value: 'string', | ||
total: undefined, | ||
expected: undefined, | ||
}, | ||
{ | ||
testName: 'negative value with existing total', | ||
value: -1, | ||
total: 100, | ||
expected: 99, | ||
}, | ||
{ | ||
testName: 'zero value with existing total', | ||
value: 0, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
{ | ||
testName: 'positive value with existing total', | ||
value: 1, | ||
total: 100, | ||
expected: 101, | ||
}, | ||
{ | ||
testName: 'null value with existing total', | ||
value: null, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
{ | ||
testName: 'undefined value with existing total', | ||
value: undefined, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
{ | ||
testName: 'string value with existing total', | ||
value: 'string', | ||
total: 100, | ||
expected: 100, | ||
}, | ||
] | ||
|
||
describe('addToTotalIfNumber', () => { | ||
tests.forEach((t) => { | ||
it(t.testName, () => { | ||
expect(addToTotalIfNumber(t.value, t.total)).toEqual(t.expected) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const addToTotalIfNumber = (value, total) => | ||
typeof value === 'number' && Number.isFinite(value) | ||
? (total ?? 0) + value | ||
: total |