Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Try with render seems to stop execution of other tests #316

Open
dshenderson opened this issue Jun 17, 2021 · 0 comments
Open

Using Try with render seems to stop execution of other tests #316

dshenderson opened this issue Jun 17, 2021 · 0 comments

Comments

@dshenderson
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant