to-be-in-the-document.js 971 B

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.toBeInTheDocument = toBeInTheDocument;
  6. var _utils = require("./utils");
  7. function toBeInTheDocument(element) {
  8. if (element !== null || !this.isNot) {
  9. (0, _utils.checkHtmlElement)(element, toBeInTheDocument, this);
  10. }
  11. const pass = element === null ? false : element.ownerDocument === element.getRootNode({
  12. composed: true
  13. });
  14. const errorFound = () => {
  15. return `expected document not to contain element, found ${this.utils.stringify(element.cloneNode(true))} instead`;
  16. };
  17. const errorNotFound = () => {
  18. return `element could not be found in the document`;
  19. };
  20. return {
  21. pass,
  22. message: () => {
  23. return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toBeInTheDocument`, 'element', ''), '', // eslint-disable-next-line babel/new-cap
  24. this.utils.RECEIVED_COLOR(this.isNot ? errorFound() : errorNotFound())].join('\n');
  25. }
  26. };
  27. }