paralleldrive / paralleldrive/riteway

Using Try with render seems to stop execution of other tests

Open
#316 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.2k
Forks
40
Avg merge
4h 53m
Merged PRs (30d)
7

Description

I have created a useStore consumer hook to access context in my TypeScript React app following the pattern recommended by Kent C. Dodds:

export const useStore = () => {
  const context = useContext(StoreContext);
  if (context === undefined) {
    throw new Error('useStore must be used within a StoreProvider');
  }
  return context;
};

I want to test that the error is thrown when context is undefined, so I've written the following test using render and Try:

import React, { ReactElement } from 'react';
import { describe, Try } from 'riteway';
import render from 'riteway/render-component';
import { useStore } from './Store.provider';

const ContextlessComponent = (): ReactElement => {
  const { state } = useStore();
  return <>{state.toString()}</>;
};

describe('Store/Store.provider/useStore()', async (assert) => {
  assert({
    given: 'useStore() is called without a StoreProvider',
    should: 'throw an error',
    actual: Try(render, <ContextlessComponent />).message,
    expected: 'useStore must be used within a StoreProvider',
  });
});

The test passes, but no further tests get run after this one.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the shown test with riteway's Try and render entry points, including riteway/render-component, and observe whether the thrown useStore error prevents subsequent tests from running. Done means the error assertion still passes and later tests execute normally; the payload does not name a specific source file or existing test to inspect.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.