-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(utils): increase test coverage chunk 1
- Loading branch information
Arturo Riveron Borodovisina
committed
Mar 28, 2022
1 parent
679d32e
commit 9960a13
Showing
15 changed files
with
512 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* @flow */ | ||
|
||
import { awaitKey } from '../../../src'; | ||
|
||
describe('awaitKey cases', () => { | ||
it('awaitKey should return the value when existing', () => { | ||
const obj = { | ||
custom: true | ||
}; | ||
const result = awaitKey(obj, 'custom'); | ||
|
||
if (!result) { | ||
throw new Error(`should return "true", but got: ${ result }`); | ||
} | ||
}); | ||
|
||
it('awaitKey should return the configured value when does not exists', () => { | ||
const obj = {}; | ||
|
||
awaitKey(obj, 'custom'); | ||
obj.custom = 'result'; | ||
const result = obj.custom; | ||
|
||
if (result !== 'result') { | ||
throw new Error(`should return "result", but got: ${ result }`); | ||
} | ||
}); | ||
}); |
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,130 @@ | ||
/* @flow */ | ||
|
||
import { | ||
perc, min, max, roundUp, regexMap, svgToBase64, | ||
objFilter, regexTokenize, camelToDasherize, dasherizeToCamel, | ||
capitalizeFirstLetter, arrayFrom, isObject, isObjectObject | ||
} from '../../../src/util'; | ||
|
||
describe('util cases', () => { | ||
const sourceValues = [ 7, 30, 1 ]; | ||
|
||
it('perc', () => { | ||
const result = perc(1000, 50); | ||
|
||
if (result !== 500) { | ||
throw new Error(`should return the value "500", but got: ${ result }`); | ||
} | ||
}); | ||
|
||
it('min', () => { | ||
const result = min(...sourceValues); | ||
|
||
if (result !== 1) { | ||
throw new Error(`should return the minimum value "1", but got: ${ result }`); | ||
} | ||
}); | ||
|
||
it('max', () => { | ||
const result = max(...sourceValues); | ||
|
||
if (result !== 30) { | ||
throw new Error(`should return the maximum value "30", but got: ${ result }`); | ||
} | ||
}); | ||
|
||
it('roundUp', () => { | ||
const result = roundUp(10, 5); | ||
|
||
if (result !== 10) { | ||
throw new Error(`should return the roundUp value "10", but got: ${ result }`); | ||
} | ||
}); | ||
|
||
it('roundUp', () => { | ||
const result = roundUp(10, 6); | ||
|
||
if (result !== 12) { | ||
throw new Error(`should return the roundUp value "12", but got: ${ result }`); | ||
} | ||
}); | ||
|
||
it('regexMap', () => { | ||
const expectedResult = 'test'; | ||
// $FlowFixMe incompatible-call | ||
const result = regexMap(expectedResult, /[a-z]*/); | ||
|
||
if (result[0] !== expectedResult) { | ||
throw new Error(`should get the value "${ expectedResult }", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('svgToBase64', () => { | ||
const expectedResult = 'data:image/svg+xml;base64,YQ'; | ||
// $FlowFixMe incompatible-call | ||
const result = svgToBase64('a'); | ||
|
||
if (result !== expectedResult) { | ||
throw new Error(`should get the value "${ expectedResult }", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('objFilter', () => { | ||
const result = objFilter({ value: true, value1: false }, value => value); | ||
|
||
if (!result.value) { | ||
throw new Error(`should get the value "true" from key, but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('regexTokenize', () => { | ||
const expectedResult = 'test'; | ||
const result = regexTokenize(expectedResult, /[a-z]+/); | ||
|
||
if (result[0] !== expectedResult) { | ||
throw new Error(`should get the value "${ expectedResult }" from key, but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('camelToDasherize and dasherizeToCamel', () => { | ||
const dasherize = camelToDasherize('TestCase'); | ||
const undasherize = dasherizeToCamel(dasherize); | ||
|
||
if (dasherize !== '-test-case' || undasherize !== 'TestCase') { | ||
throw new Error(`should dasherize and undasherize values, but got dasherize: ${ String(dasherize) } and undasherize: ${ undasherize }`); | ||
} | ||
}); | ||
|
||
it('capitalizeFirstLetter', () => { | ||
const expectedResult = 'Test'; | ||
const result = capitalizeFirstLetter('test'); | ||
|
||
if (result !== expectedResult) { | ||
throw new Error(`should return the value "${ expectedResult }", but got ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('arrayFrom', () => { | ||
const result = arrayFrom([ 1, 2, 3 ]); | ||
|
||
if (result.length !== 3) { | ||
throw new Error(`should return an array with length "3", but got ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('isObject', () => { | ||
const result = isObject({}); | ||
|
||
if (!result) { | ||
throw new Error(`should return the value "true", but got ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('isObjectObject', () => { | ||
const result = isObjectObject({}); | ||
|
||
if (!result) { | ||
throw new Error(`should return the value "true", but got ${ String(result) }`); | ||
} | ||
}); | ||
}); |
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,38 @@ | ||
/* @flow */ | ||
|
||
import { deserializePrimitive } from '../../../src'; | ||
|
||
describe('deserializePrimitive cases', () => { | ||
it('deserializePrimitive should return true', () => { | ||
const result = deserializePrimitive('true'); | ||
|
||
if (result !== true) { | ||
throw new Error(`should return "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('deserializePrimitive should return false', () => { | ||
const result = deserializePrimitive('false'); | ||
|
||
if (result !== false) { | ||
throw new Error(`should return "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('deserializePrimitive should return numeric value', () => { | ||
const result = deserializePrimitive('10'); | ||
|
||
if (result !== 10) { | ||
throw new Error(`should return "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
|
||
it('deserializePrimitive should return float value', () => { | ||
const result = deserializePrimitive('10.57'); | ||
|
||
if (result !== 10.57) { | ||
throw new Error(`should return "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
}); |
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,38 @@ | ||
/* @flow */ | ||
|
||
import { get } from '../../../src'; | ||
|
||
describe('get cases', () => { | ||
const expectedResult = 10; | ||
it('get should return default value', () => { | ||
const result = get({}, '', expectedResult); | ||
|
||
if (result !== expectedResult) { | ||
throw new Error(`should return value "10", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('get should get deep keys', () => { | ||
const result = get({ value: { result: expectedResult } }, 'value.result'); | ||
|
||
if (result !== expectedResult) { | ||
throw new Error(`should return value "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('get should get deep keys', () => { | ||
const result = get({ value: { result: expectedResult } }, 'value.result'); | ||
|
||
if (result !== expectedResult) { | ||
throw new Error(`should return value "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
|
||
it('get should get deep keys with default value', () => { | ||
const result = get({}, 'value.result', expectedResult); | ||
|
||
if (result !== expectedResult) { | ||
throw new Error(`should return value "true", but got: ${ String(result) }`); | ||
} | ||
}); | ||
}); |
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,13 @@ | ||
/* @flow */ | ||
|
||
import { match } from '../../../src'; | ||
|
||
describe('match cases', () => { | ||
it('match should return original function', () => { | ||
const result = match('letters', /(t[a-z]*)/i); | ||
|
||
if (result !== 'tters') { | ||
throw new Error(`should return "tters", but got: ${ String(result) }`); | ||
} | ||
}); | ||
}); |
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,23 @@ | ||
/* @flow */ | ||
|
||
import { patchMethod } from '../../../src'; | ||
|
||
describe('patchMethod cases', () => { | ||
it('patchMethod should return original function', () => { | ||
const obj = { | ||
custom() : string { | ||
return 'first'; | ||
} | ||
}; | ||
const handler = ({ callOriginal }) => { | ||
return callOriginal(); | ||
}; | ||
|
||
patchMethod(obj, 'custom', handler); | ||
const result = obj.custom(); | ||
|
||
if (result !== 'first') { | ||
throw new Error(`should return "first", but got: ${ result }`); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.