Skip to content

when using waitForDomChange on chrome 70 : setImmediate is not defined #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brucou opened this issue Dec 17, 2018 · 16 comments
Closed

when using waitForDomChange on chrome 70 : setImmediate is not defined #184

brucou opened this issue Dec 17, 2018 · 16 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed released

Comments

@brucou
Copy link
Contributor

brucou commented Dec 17, 2018

  • dom-testing-library version:
    3.16.1
  • react version:
    not using react
  • node version:
    v8.2.0
  • npm (or yarn) version:
    v5.3.0

Relevant code or config:

  waitForDomChange({ container: root })

What you did:

I ran tests in the browser with QUnit and dom-testing-library.
I tried to use the waitForDomChange API.

What happened:

Uncaught ReferenceError: setImmediate is not defined
    at onDone (dom-testing-library.js:4344)
    at MutationObserver.<anonymous> (dom-testing-library.js:4338)

Reproduction:

can't reproduce in codesandbox. When I try to import {waitForDomChange} from "dom-testing-library" :

(0 , _domTestingLibrary.waitForDomChange) is not a function

Problem description:

That code from the library use a function which is not defined in chrome :

function waitForDomChange(_temp) {
    var _ref = _temp === void 0 ? {} : _temp,
      _ref$container = _ref.container,
      container = _ref$container === void 0 ? getDocument() : _ref$container,
      _ref$timeout = _ref.timeout,
      timeout = _ref$timeout === void 0 ? 4500 : _ref$timeout,
      _ref$mutationObserver = _ref.mutationObserverOptions,
      mutationObserverOptions = _ref$mutationObserver === void 0 ? {
        subtree: true,
        childList: true,
        attributes: true,
        characterData: true
      } : _ref$mutationObserver;

    return new Promise(function (resolve, reject) {
      var timer = setTimeout(function () {
        onDone(new Error('Timed out in waitForDomChange.'), null);
      }, timeout);
      var observer = newMutationObserver(function (mutationsList) {
        onDone(null, mutationsList);
      });
      observer.observe(container, mutationObserverOptions);

      function onDone(error, result) {
        clearTimeout(timer);
        setImmediate(function () {
          return observer.disconnect();
        });

        if (error) {
          reject(error);
        } else {
          resolve(result);
        }
      }
    });
  }
@alexkrolick
Copy link
Collaborator

Very strange - checking the console for this page (github): window.setTimeout and window.setInterval are both available as globals, but window.setImmediate is not. It's probably polyfilled in.

https://caniuse.com/#search=setImmediate

setTimeout(fn, 0) should be a fine replacement

@brucou
Copy link
Contributor Author

brucou commented Dec 18, 2018

yeah it is used in only 5% of the browsers... I mocked it as you suggested, but that would be much better replaced at the source. What do you think? It is only used in two places in the code, for waitForDomChange and waitForElement.

I bet this has not appeared so far because nobody used the library in a real browser, like I do, so there are all sorts of discrepancies appearing vs. jsdom and the copycats.

@alexkrolick
Copy link
Collaborator

Yes, it should be replaced in the library. Care to make a PR?

@brucou
Copy link
Contributor Author

brucou commented Dec 18, 2018

eer how do I do that? ok, I just have to create a branch I see. Will do that tomorrow first thing

@kentcdodds
Copy link
Member

kentcdodds commented Dec 18, 2018

Hi @brucou 👋

We're here to help you! Start here: http://makeapullrequest.com

Let us know if you need help!

@brucou
Copy link
Contributor Author

brucou commented Dec 18, 2018

amazing, looking forward to reading it. I always wondered how that works.

@kentcdodds
Copy link
Member

@brucou,

Are you still interested in making this contribution?

@kentcdodds kentcdodds added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Jan 3, 2019
@brucou
Copy link
Contributor Author

brucou commented Jan 3, 2019

xmas and new year\s eve got in the way. Still have a tough week. If there is no rush, let a week pass and if I haven't done anything about it by then, then go ahead and do the change. Would that work?

@kentcdodds
Copy link
Member

Yep! No worries 😁

@brucou
Copy link
Contributor Author

brucou commented Jan 4, 2019

one question : there is a __tests__ directory with jest tests. I am going to test this feature in a real browser, so is it ok if I use Qunit? and create another directory called tests instead of tests? or what do you advise?

@kentcdodds
Copy link
Member

That's a great point @brucou. I'm not sure. I think it'd probably be cool to have a test or two that run in a real browser (using Karma), but I think I'd rather use mocha for two reasons:

  1. I'm personally more familiar with mocha
  2. mocha is a LOT more widely used than Qunit

I don't think it's absolutely necessary to have tests that run in a real browser, but if you really would like to do this then you're welcome to do so :)

brucou pushed a commit to brucou/dom-testing-library that referenced this issue Jan 4, 2019
brucou pushed a commit to brucou/dom-testing-library that referenced this issue Jan 4, 2019
@brucou
Copy link
Contributor Author

brucou commented Jan 4, 2019 via email

@kentcdodds
Copy link
Member

Fixed! Thanks!

@kentcdodds
Copy link
Member

🎉 This issue has been resolved in version 3.16.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@brucou
Copy link
Contributor Author

brucou commented Jan 7, 2019

Forgot to thank you for the support Kent and Alex in making that pull request. That was really appreciated! and the learning material is awesome.

@kentcdodds
Copy link
Member

Awesome! Congrats on the PR @brucou! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed released
Projects
None yet
Development

No branches or pull requests

3 participants