Jest: Complex Test Case — Part2
At last Part(Part1), I implemented Testing with Simple Test Case.
However I wanted to run ton of tests for ‘ready’ state for another valid Pass State.
I decided to create new function to run test with ‘when’ and ‘expected’.
Test Case For Specific State
First, I defined new Type containing params of the target function.
‘when’ contains all parameters for the target function.
when: PassValidationParam
Test Function wrapping Tests
Second, I wrapped test codes for ‘ready’ state with new function
Pass the Pass State for testing
const testValidCase = (passState: PassState) => {
And wrapped original tests with new ‘describe’ to specify State
pass.state = passState
Running Tests with State List
All tests for ‘ready’ passed for ‘Using’ state too. 😀
However I couldn’t run test only one state in IDE.
When I press ‘Debug’, any test didn’t perform.😫
Test only one state
I thought how can I solve this? 🤔
First, splits forEach to describes
And I could see ‘Debug’ button
However ‘describe’ message were duplicated when I running test. 😞
I solved this problem by just deleting ‘describe’ from the test function.
Now I can run tests for only one state! 😃