Sha256: 7208147916eefc8f7ebfd0146aab9e73c4e0ffa836bb30972b1c198d00cdee5e

Contents?: true

Size: 1.68 KB

Versions: 26

Compression:

Stored size: 1.68 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.waitForElementToBeRemoved = waitForElementToBeRemoved;
var _waitFor = require("./wait-for");
const isRemoved = result => !result || Array.isArray(result) && !result.length;

// Check if the element is not present.
// As the name implies, waitForElementToBeRemoved should check `present` --> `removed`
function initialCheck(elements) {
  if (isRemoved(elements)) {
    throw new Error('The element(s) given to waitForElementToBeRemoved are already removed. waitForElementToBeRemoved requires that the element(s) exist(s) before waiting for removal.');
  }
}
async function waitForElementToBeRemoved(callback, options) {
  // created here so we get a nice stacktrace
  const timeoutError = new Error('Timed out in waitForElementToBeRemoved.');
  if (typeof callback !== 'function') {
    initialCheck(callback);
    const elements = Array.isArray(callback) ? callback : [callback];
    const getRemainingElements = elements.map(element => {
      let parent = element.parentElement;
      if (parent === null) return () => null;
      while (parent.parentElement) parent = parent.parentElement;
      return () => parent.contains(element) ? element : null;
    });
    callback = () => getRemainingElements.map(c => c()).filter(Boolean);
  }
  initialCheck(callback());
  return (0, _waitFor.waitFor)(() => {
    let result;
    try {
      result = callback();
    } catch (error) {
      if (error.name === 'TestingLibraryElementError') {
        return undefined;
      }
      throw error;
    }
    if (!isRemoved(result)) {
      throw timeoutError;
    }
    return undefined;
  }, options);
}

/*
eslint
  require-await: "off"
*/

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/@testing-library/dom/dist/wait-for-element-to-be-removed.js