-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react): add assertion function to assert condition (#159)
* fix(assert): add assertion function to assert condition * Create spotty-rocks-dance.md * Update .changeset/spotty-rocks-dance.md * Update packages/react/src/utils/assert.ts Co-authored-by: 박찬혁 <[email protected]> * test(react): modify assertion test code. (#162) * fix(react): add assertion function to assert conditionchange some test code * fix(react): revert script * Update packages/react/src/utils/assert.spec.ts Co-authored-by: Jonghyeon Ko <[email protected]> * Update packages/react/src/utils/assert.spec.ts Co-authored-by: Jonghyeon Ko <[email protected]> * Update packages/react/src/utils/assert.spec.ts Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: Jonghyeon Ko <[email protected]> --------- Co-authored-by: 박찬혁 <[email protected]>
- Loading branch information
Showing
4 changed files
with
45 additions
and
0 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,5 @@ | ||
--- | ||
"@suspensive/react": patch | ||
--- | ||
|
||
fix(react): add assertion function to assert condition |
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,34 @@ | ||
import { assert } from '.' | ||
|
||
function get(type: 'foo' | 'bar') { | ||
switch (type) { | ||
case 'foo': | ||
return { | ||
foo1: 'foo1', | ||
foo2: 'foo2', | ||
} as const | ||
case 'bar': | ||
return { | ||
bar1: 'bar1', | ||
bar2: 'bar2', | ||
} as const | ||
default: { | ||
throw new Error('no type') | ||
} | ||
} | ||
} | ||
|
||
describe('assert', () => { | ||
// eslint-disable-next-line vitest/expect-expect | ||
it('should assert condition', () => { | ||
const data = get('foo') | ||
assert(data.foo1 === 'foo1', 'dummy-message') | ||
expectTypeOf(data.foo2).toMatchTypeOf<string>() | ||
expectTypeOf(data.bar1).not.toMatchTypeOf<string>() | ||
}) | ||
|
||
it('should throw error if given condition is not met', () => { | ||
const value = 'baz' as string | ||
expect(() => assert(value === 'paz', "value should be 'paz'")).toThrow("value should be 'paz'") | ||
}) | ||
}) |
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,5 @@ | ||
export function assert(condition: boolean, message: string): asserts condition { | ||
if (!condition) { | ||
throw new Error(message) | ||
} | ||
} |
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,2 +1,3 @@ | ||
export { hasResetKeysChanged } from './hasResetKeysChanged' | ||
export { hashKey } from './hashKey' | ||
export { assert } from './assert' |
eac6832
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.
Successfully deployed to the following URLs:
visualization – ./websites/visualization
visualization-git-main-suspensive.vercel.app
visualization.suspensive.org
visualization-suspensive.vercel.app