Jest: Complex Test Case — Part2

Lee young-jun
2 min readNov 13, 2021

--

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.

Tests for ‘Ready’ 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

Running tests with valid Pass States

All tests for ‘ready’ passed for ‘Using’ state too. 😀

However I couldn’t run test only one state in IDE.

Jest Plugin

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. 😞

Duplicated Describe Message

I solved this problem by just deleting ‘describe’ from the test function.

Now I can run tests for only one state! 😃

Tests splited to describes

--

--

No responses yet