-
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.
- Loading branch information
Showing
1 changed file
with
13 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,84 @@ | ||
import { addToTotalIfNumber } from '../addToTotalIfNumber.js' | ||
|
||
const field = 'test' | ||
const tests = [ | ||
{ | ||
testName: 'negative value', | ||
value: -1, | ||
totalObj: {}, | ||
field, | ||
total: undefined, | ||
expected: -1, | ||
}, | ||
{ | ||
testName: 'zero value', | ||
value: 0, | ||
totalObj: {}, | ||
field, | ||
total: undefined, | ||
expected: 0, | ||
}, | ||
{ | ||
testName: 'positive value', | ||
value: 1, | ||
totalObj: {}, | ||
field, | ||
total: undefined, | ||
expected: 1, | ||
}, | ||
{ | ||
testName: 'null value', | ||
value: null, | ||
totalObj: {}, | ||
field, | ||
total: undefined, | ||
expected: undefined, | ||
}, | ||
{ | ||
testName: 'undefined value', | ||
value: undefined, | ||
totalObj: {}, | ||
field, | ||
total: undefined, | ||
expected: undefined, | ||
}, | ||
{ | ||
testName: 'string value', | ||
value: 'string', | ||
totalObj: {}, | ||
field, | ||
total: undefined, | ||
expected: undefined, | ||
}, | ||
{ | ||
testName: 'negative value with existing total', | ||
value: -1, | ||
totalObj: { [field]: 100 }, | ||
field, | ||
total: 100, | ||
expected: 99, | ||
}, | ||
{ | ||
testName: 'zero value with existing total', | ||
value: 0, | ||
totalObj: { [field]: 100 }, | ||
field, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
{ | ||
testName: 'positive value with existing total', | ||
value: 1, | ||
totalObj: { [field]: 100 }, | ||
field, | ||
total: 100, | ||
expected: 101, | ||
}, | ||
{ | ||
testName: 'null value with existing total', | ||
value: null, | ||
totalObj: { [field]: 100 }, | ||
field, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
{ | ||
testName: 'undefined value with existing total', | ||
value: undefined, | ||
totalObj: { [field]: 100 }, | ||
field, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
{ | ||
testName: 'string value with existing total', | ||
value: 'string', | ||
totalObj: { [field]: 100 }, | ||
field, | ||
total: 100, | ||
expected: 100, | ||
}, | ||
] | ||
|
||
describe('addToTotalIfNumber', () => { | ||
tests.forEach((t) => { | ||
it(t.testName, () => { | ||
expect(addToTotalIfNumber(t.value, t.totalObj[t.field])).toEqual( | ||
t.expected | ||
) | ||
expect(addToTotalIfNumber(t.value, t.total)).toEqual(t.expected) | ||
}) | ||
}) | ||
}) |