Skip to content
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

ElementQueries don't work with PhantomJS #237

Open
Unkrass opened this issue Jul 23, 2018 · 2 comments
Open

ElementQueries don't work with PhantomJS #237

Unkrass opened this issue Jul 23, 2018 · 2 comments

Comments

@Unkrass
Copy link

Unkrass commented Jul 23, 2018

I am using the CSS element queries 1.0.2 with Emberjs. Every time I start the Ember tests with PhantomJS Prebuilt 2.1.14, I get the error TypeError: null is not an object (evaluating 'styles.getPropertyValue('animation-name').index
Of')
which comes from this function (lines 410-426) in ElementQueries.js.

document.body.addEventListener(animationStart, function (e) {
 var element = e.target;
 var styles = window.getComputedStyle(element, null);

   if (-1 !== styles.getPropertyValue('animation-name').indexOf('element-queries')) {
    element.elementQueriesSensor = new ResizeSensor(element, function () {
     if (element.elementQueriesSetupInformation) {
      element.elementQueriesSetupInformation.call();
     }
    });

    var sensorStyles = window.getComputedStyle(element.resizeSensor, null);
    var id = sensorStyles.getPropertyValue('min-width');
    id = parseInt(id.replace('px', ''));
    setupElement(e.target, idToSelectorMapping[id]);
   }
 });

This only fails with PhantomJS and is fine in browser tests with Chrome, so I assume there might be something wrong in general when using element queries with headless browsers or maybe only with PhantomJS. My attempt at implementing a sanity check was wrapping styles.getPropertyValue('animation-name') !== null around the two if conditions, which seems to work. Is that of any use?

@marcj
Copy link
Owner

marcj commented Jul 23, 2018

Mh, getComputedStyle should work in headless as well. Have you tried headless chrome? https://github.com/GoogleChrome/puppeteer

@Unkrass
Copy link
Author

Unkrass commented Aug 6, 2018

What I didn't know was that my co-worker tried out the ElementQueries but deleted everything except the import and the listener, so we could just remove the import and the listener and the tests worked just fine. Replacing PhantomJS with Puppeteer was no option, so if you say it works in Puppeteer this might be a PhantomJS thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants