Home / File/ IntersectionMocks.js — react Source File

IntersectionMocks.js — react Source File

Architecture documentation for IntersectionMocks.js, a javascript file in the react codebase.

File javascript BabelCompiler Validation 5 functions 1 classes

Entity Profile

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.
 *
 */

const intersectionObserverMock = {callback: null, observedTargets: []};

/**
 * This is a broken polyfill.
 * It is only intended to provide bare minimum test coverage.
 * More meaningful tests will require the use of fixtures.
 */
export function mockIntersectionObserver() {
  intersectionObserverMock.callback = null;
  intersectionObserverMock.observedTargets = [];

  class IntersectionObserver {
    constructor() {
      intersectionObserverMock.callback = arguments[0];
    }

    disconnect() {
      intersectionObserverMock.callback = null;
      intersectionObserverMock.observedTargets.splice(0);
    }

    observe(target) {
      intersectionObserverMock.observedTargets.push(target);
    }

    unobserve(target) {
      const index = intersectionObserverMock.observedTargets.indexOf(target);
      if (index >= 0) {
        intersectionObserverMock.observedTargets.splice(index, 1);
      }
    }
  }

  window.IntersectionObserver = IntersectionObserver;

  return intersectionObserverMock;
}

export function simulateIntersection(...entries) {
  intersectionObserverMock.callback(
    entries.map(([target, rect, ratio]) => ({
      boundingClientRect: {
        top: rect.y,
        left: rect.x,
        width: rect.width,
        height: rect.height,
      },
      intersectionRatio: ratio,
      target,
    })),
  );
}
// ... (91 more lines)

Domain

Subdomains

Frequently Asked Questions

What does IntersectionMocks.js do?
IntersectionMocks.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in IntersectionMocks.js?
IntersectionMocks.js defines 5 function(s): mockIntersectionObserver, mockRangeClientRects, setBoundingClientRect, setClientRects, simulateIntersection.
Where is IntersectionMocks.js in the architecture?
IntersectionMocks.js is located at packages/react-dom/src/__tests__/utils/IntersectionMocks.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-dom/src/__tests__/utils).

Analyze Your Own Codebase

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

Try Supermodel Free