nx/packages/react/src/utils/assertion.spec.ts
Nicholas Cunningham 2c55685492
fix(react): update react router logic with selected bundler (#30399)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
Currently, when you generate a react app and select `--use-react-router`
and `--bundler=` any other bundler except `vite` you would be forced
into using `vite`

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
When you generate a React app and opt into using `--use-react-router`
with `--bundler=webpack` (for example) you will get an error stating the
React Router can only be used with `vite`.

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-03-24 09:45:23 -06:00

36 lines
1.1 KiB
TypeScript

import { assertValidStyle, assertValidReactRouter } from './assertion';
describe('assertValidStyle', () => {
it('should accept style option values from app, lib, component schematics', () => {
const schemas = [
require('../generators/application/schema.json'),
require('../generators/component/schema.json'),
require('../generators/library/schema.json'),
];
schemas.forEach((schema) => {
const values = schema.properties.style['x-prompt'].items;
expect(() =>
values.forEach((value) => assertValidStyle(value)).not.toThrow()
);
});
});
it('should throw for invalid values', () => {
expect(() => assertValidStyle('bad')).toThrow(/Unsupported/);
});
it('should throw for invalid react-router and bundler combination', () => {
expect(() => assertValidReactRouter(true, 'webpack')).toThrow(
/Unsupported/
);
expect(() => assertValidReactRouter(true, 'rspack')).toThrow(/Unsupported/);
expect(() => assertValidReactRouter(true, 'rsbuild')).toThrow(
/Unsupported/
);
expect(() => assertValidReactRouter(true, 'vite')).not.toThrow(
/Unsupported/
);
});
});