main
ts 40 lines 1.32 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8 import {Effect, validateEnvironmentConfig} from '..';
9 import {ValueKind} from '../HIR';
10
11 describe('parseConfigPragma()', () => {
12 it('passing null throws', () => {
13 expect(() => validateEnvironmentConfig(null as any)).toThrow();
14 });
15
16 // tests that the error message remains useful
17 it('passing incorrect value throws', () => {
18 expect(() => {
19 validateEnvironmentConfig({
20 validateHooksUsage: 1,
21 } as any);
22 }).toThrowErrorMatchingInlineSnapshot(
23 `"Error: Could not validate environment config. Update React Compiler config to fix the error. Validation error: Invalid input: expected boolean, received number at "validateHooksUsage"."`,
24 );
25 });
26
27 it('can parse stringy enums', () => {
28 const stringyHook = {
29 effectKind: 'freeze',
30 valueKind: 'frozen',
31 };
32 const env = {
33 customHooks: new Map([['useFoo', stringyHook]]),
34 };
35 const validatedEnv = validateEnvironmentConfig(env as any);
36 const validatedHook = validatedEnv.customHooks.get('useFoo');
37 expect(validatedHook?.effectKind).toBe(Effect.Freeze);
38 expect(validatedHook?.valueKind).toBe(ValueKind.Frozen);
39 });
40 });