# How testing \`condition\` blocks and signals (Manual time skipping?)

**URL:** <https://community.temporal.io/t/how-testing-condition-blocks-and-signals-manual-time-skipping/7243>\
**Category:** Community Support\
**Tags:** testing, typescript-sdk\
**Created:** [February 11, 2023, 10:30pm UTC](https://community.temporal.io/t/how-testing-condition-blocks-and-signals-manual-time-skipping/7243 "2023-02-11T22:30:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Kaplan](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ian_kaplan/32/3310_2.png) [@Ian\_Kaplan](https://community.temporal.io/u/Ian_Kaplan)\
**Post date:** [February 11, 2023, 10:30pm UTC](https://community.temporal.io/t/how-testing-condition-blocks-and-signals-manual-time-skipping/7243/1 "2023-02-11T22:30:02Z")

</div>

Hey there.

Working through some of the samples since i want to use temporal to solve a subscription use case. Im not sure how to test the following code in jest to show that when a cancel signal is received the subscription is terminated early (and the mock billing method is called \< maxBillingPeriod).

```plaintext
async function BillingCycle(customer: Customer) {

  const status = useSubscriptionStore();
  const { maxBillingPeriods, billingPeriod} = customer;

  // Charge the customer at the end of each billing period
  while (status.value.billingPeriodsCharged < maxBillingPeriods) {

    if (await condition((() => status.value.isCanceled), billingPeriod)) {
      break;
    }    
    await chargeCustomerForBillingPeriod(customer);
    status.value.billingPeriodsCharged += 1;
  }
  await sendSubscriptionOverEmail(customer.email);
}

```

I get automatic time skippping from the [Testing TypeScript Workflows | Legacy documentation for Temporal SDKs](https://legacy-documentation-sdks.temporal.io/typescript/testing) docs but manual time skipping doesnt seem to work. when i use `start()` instead of `execute` to start the test environment workflow my jest throws a timeout error meaning there is something wrong with the timeskipping sleep method. My test is written something like…

```auto
    it('cancels a subscription', async () => {
        const worker = await Worker.create({
            connection: testEnv.nativeConnection,
            taskQueue: 'test',
            activities: mockActivities,
            workflowsPath: require.resolve('./workflows'),
        });

        const handle = await testEnv.client.workflow.start(SubscriptionWorkflow, {
            args: [{
                email: 'ian-kaplan-2',
                billingPeriod: '30 seconds',
                trialPeriod: '30 seconds',
                maxBillingPeriods: 5,
                initialBillingPeriodCharge: 10,
                id: 'ian-kaplan-2',
            }],
            workflowId: 'workflow-1',
            taskQueue: 'test',
        });
        await testEnv.sleep(1000 * 50);
        await handle.signal(cancelSubscription);
        await handle.cancel()
        expect(mockActivities.chargeCustomerForBillingPeriod).toBeCalledTimes(1);
    });

```

any help would be appreciated. thanks!

---

<div class="post-metadata">

**Author:** ![bergundy](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/bergundy/32/900_2.png) [@bergundy](https://community.temporal.io/u/bergundy)\
**Post date:** [February 12, 2023, 6:23am UTC](https://community.temporal.io/t/how-testing-condition-blocks-and-signals-manual-time-skipping/7243/2 "2023-02-12T06:23:12Z")

</div>

It doesn’t look like you’re running the worker in the test.

---

<div class="post-metadata">

**Author:** ![Ian\_Kaplan](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/ian_kaplan/32/3310_2.png) [@Ian\_Kaplan](https://community.temporal.io/u/Ian_Kaplan)\
**Post date:** [February 12, 2023, 12:44pm UTC](https://community.temporal.io/t/how-testing-condition-blocks-and-signals-manual-time-skipping/7243/3 "2023-02-12T12:44:13Z")

</div>

@bergundy at what point would i run the worker? i treid calling `worker.run()` after creating the worker and i get the same timeout. How would i start the worker in this case given that im calling `workflow.start` and not `workflow.execute`?

---

<div class="post-metadata">

**Author:** ![bergundy](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/bergundy/32/900_2.png) [@bergundy](https://community.temporal.io/u/bergundy)\
**Post date:** [February 15, 2023, 5:45pm UTC](https://community.temporal.io/t/how-testing-condition-blocks-and-signals-manual-time-skipping/7243/4 "2023-02-15T17:45:36Z")

</div>

I recommend running the worker with `runUntil` and putting the entire contents of the client code (including the sleep) in the async block.

See this example: [Testing TypeScript Workflows | Legacy documentation for Temporal SDKs](https://legacy-documentation-sdks.temporal.io/typescript/testing#time-skipping-in-activities)  
And note that `runUntil` accepts an async function or promise.
