-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: introduce EnumRecord utility methods
- Loading branch information
1 parent
74ca112
commit 047d4cd
Showing
12 changed files
with
9,134 additions
and
11,863 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' }}], | ||
'@babel/preset-typescript', | ||
], | ||
}; |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,53 @@ | ||
import { enumRecordFor, enumSizeFor, enumValuesFor } from './types'; | ||
|
||
enum Currency { | ||
USD = 'US Dollar', | ||
EUR = 'Euro' | ||
} | ||
|
||
enum Ranking { | ||
FIRST = 1, | ||
SECOND = 2, | ||
THIRD = 3 | ||
} | ||
|
||
describe('enumValuesFor', () => { | ||
it('returns an array of string enum values', () => { | ||
expect(enumValuesFor(Currency)).toEqual([Currency.USD, Currency.EUR]); | ||
}); | ||
|
||
it('returns an array of number enum values', () => { | ||
expect(enumValuesFor(Ranking)).toEqual([Ranking.FIRST, Ranking.SECOND, Ranking.THIRD]); | ||
}); | ||
}); | ||
|
||
describe('enumRecordFor', () => { | ||
it('constructs an iterable string enum record', () => { | ||
const record = enumRecordFor(Currency, (value) => value.length); | ||
expect(record).toEqual({ | ||
[Currency.USD]: 9, | ||
[Currency.EUR]: 4, | ||
}); | ||
expect(Array.from(record)).toEqual([9, 4]); | ||
}); | ||
|
||
it('constructs an iterable number enum record', () => { | ||
const record = enumRecordFor(Ranking, (value) => value * 3); | ||
expect(record).toEqual({ | ||
[Ranking.FIRST]: 3, | ||
[Ranking.SECOND]: 6, | ||
[Ranking.THIRD]: 9, | ||
}); | ||
expect(Array.from(record)).toEqual([3, 6, 9]); | ||
}); | ||
}); | ||
|
||
describe('enumSizeFor', () => { | ||
it('returns size for string enum', () => { | ||
expect(enumSizeFor(Currency)).toEqual(2); | ||
}); | ||
|
||
it('returns size for number enum', () => { | ||
expect(enumSizeFor(Ranking)).toEqual(3); | ||
}); | ||
}); |
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