-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix!: update separators #40
Conversation
const result = subject.words( | ||
'[one] two-three/four.five(six){seven}|eight_nine\\ten', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good one!
describe('with various separators', () => { | ||
const text = | ||
'[one] two-three/four.five(six){seven}|eight_nine\\ten' as const | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish for a DRYer way to write this test suite -- they're all the exact same.
There isn't a way to do the following, is there?
const text = 'abc'
const resultExpectedMap = new Map([
[subject.toUpperCase(text), 'ABC'],
// ...
])
for (const [result, expected] of resultExpectedMap.entries() {
expect(result).toEqual(expected)
type test = Expect<Equal<typeof result, typeof expected>>
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The closest I could get is this
Try 1
describe('with various separators', () => {
const text = 'abc'
const resultExpectedMap = new Map([
[subject.toUpperCase(text), 'ABC' as const],
[subject.toLowerCase(text), 'abc' as const],
// ...
])
for (const [result, expected] of resultExpectedMap.entries()) {
expect(result).toEqual(expected)
type test = Expect<Equal<typeof result, typeof expected>>
}
})
The problem with the above code is that I could switch ABC and abc on the expected side of the map and the type union would still be equal
Try 2
describe('with various separators', () => {
const text = 'abc'
const a = {
[subject.toUpperCase(text)]: 'ABC' as const,
[subject.toLowerCase(text)]: 'abc' as const,
} as const
for (const [result, expected] of Object.entries(a)) {
expect(result).toEqual(expected)
type test = Expect<Equal<typeof result, typeof expected>>
}
})
The problem with this one is that the type assertion fails (string
!== 'abc' | 'ABC'
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be easier... I personally am not a fan of too much abstractions in tests.. I tend to just repeat LOCs to avoid potential footguns.
But not against the trials
Lemme know when it is ready for review |
Should Close #35