Home / File/ Result-test.ts — react Source File

Result-test.ts — react Source File

Architecture documentation for Result-test.ts, a typescript file in the react codebase. 6 imports, 0 dependents.

File typescript TestingUtilities E2E 6 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  e18a300c_b8f4_d018_0e3a_79efdd32010e["Result-test.ts"]
  e96f281e_f381_272d_2359_3e6a091c9a1d["CompilerError.ts"]
  e18a300c_b8f4_d018_0e3a_79efdd32010e --> e96f281e_f381_272d_2359_3e6a091c9a1d
  e51fd0d2_bb38_cc97_7763_efe37f300a47["CompilerError"]
  e18a300c_b8f4_d018_0e3a_79efdd32010e --> e51fd0d2_bb38_cc97_7763_efe37f300a47
  494e3425_0b47_293a_1ea4_d4670b0fc0e7["Result.ts"]
  e18a300c_b8f4_d018_0e3a_79efdd32010e --> 494e3425_0b47_293a_1ea4_d4670b0fc0e7
  9217845a_d29d_c624_b607_e3b35cf604bc["Err"]
  e18a300c_b8f4_d018_0e3a_79efdd32010e --> 9217845a_d29d_c624_b607_e3b35cf604bc
  9f0e6a52_ff9e_00f3_1760_5fddfd89b234["Ok"]
  e18a300c_b8f4_d018_0e3a_79efdd32010e --> 9f0e6a52_ff9e_00f3_1760_5fddfd89b234
  7aace723_0ee1_cff5_b263_aec8e06dd79e["Result"]
  e18a300c_b8f4_d018_0e3a_79efdd32010e --> 7aace723_0ee1_cff5_b263_aec8e06dd79e
  style e18a300c_b8f4_d018_0e3a_79efdd32010e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {CompilerError} from '../CompilerError';
import {Err, Ok, Result} from '../Utils/Result';

function addMax10(a: number, b: number): Result<number, string> {
  const n = a + b;
  return n > 10 ? Err(`${n} is too high`) : Ok(n);
}

function onlyFoo(foo: string): Result<string, string> {
  return foo === 'foo' ? Ok(foo) : Err(foo);
}

class CustomDummyError extends Error {}

describe('Result', () => {
  test('.map', () => {
    expect(addMax10(1, 1).map(n => n * 2)).toEqual(Ok(4));
    expect(addMax10(10, 10).map(n => n * 2)).toEqual(Err('20 is too high'));
  });

  test('.mapErr', () => {
    expect(addMax10(1, 1).mapErr(e => `not a number: ${e}`)).toEqual(Ok(2));
    expect(addMax10(10, 10).mapErr(e => `couldn't add: ${e}`)).toEqual(
      Err("couldn't add: 20 is too high"),
    );
  });

  test('.mapOr', () => {
    expect(onlyFoo('foo').mapOr(42, v => v.length)).toEqual(3);
    expect(onlyFoo('bar').mapOr(42, v => v.length)).toEqual(42);
  });

  test('.mapOrElse', () => {
    expect(
      onlyFoo('foo').mapOrElse(
        () => 42,
        v => v.length,
      ),
    ).toEqual(3);
    expect(
      onlyFoo('bar').mapOrElse(
        () => 42,
        v => v.length,
      ),
    ).toEqual(42);
  });

  test('.andThen', () => {
    expect(addMax10(1, 1).andThen(n => Ok(n * 2))).toEqual(Ok(4));
    expect(addMax10(10, 10).andThen(n => Ok(n * 2))).toEqual(
      Err('20 is too high'),
    );
  });
// ... (85 more lines)

Subdomains

Frequently Asked Questions

What does Result-test.ts do?
Result-test.ts is a source file in the react codebase, written in typescript. It belongs to the TestingUtilities domain, E2E subdomain.
What functions are defined in Result-test.ts?
Result-test.ts defines 2 function(s): addMax10, onlyFoo.
What does Result-test.ts depend on?
Result-test.ts imports 6 module(s): CompilerError, CompilerError.ts, Err, Ok, Result, Result.ts.
Where is Result-test.ts in the architecture?
Result-test.ts is located at compiler/packages/babel-plugin-react-compiler/src/__tests__/Result-test.ts (domain: TestingUtilities, subdomain: E2E, directory: compiler/packages/babel-plugin-react-compiler/src/__tests__).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free