Coder Social home page Coder Social logo

Comments (6)

eddyerburgh avatar eddyerburgh commented on May 28, 2024

Hi thanks for the issue, I'll have a look and try for a fix tomorrow

from avoriaz.

eddyerburgh avatar eddyerburgh commented on May 28, 2024

So I've changed the style method to return the computedStyles instead of just inline styles. I add the element to the DOM when style is called and run getComputedStyle on the node.

It's not ideal. getComputedStyles returns the resolved style, so setting background: red results in a computed style of rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box. Not an ideal solution.

This also breaks style when using jsdom. I'm going to look into it tomorrow, but the problem is that stylesheets aren't being rendered in jsdom (document.styleSheets).

I think it's better though to have this working in a browser than to keep the inline only implementation.

Fix is available in 1.4.0 - https://github.com/eddyerburgh/avoriaz/releases/tag/1.4.0 . Which is live on npm

from avoriaz.

eddyerburgh avatar eddyerburgh commented on May 28, 2024

After sleeping on it, I've come up with a better solution.

I've deprecated style, since it is not reasonable to expect someone to assert style.color equals rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box when your css rule is color: red.

As a solution I've added the hasStyle method. This takes a style and a value as parameters and returns a boolean. It works on all computed styles (i.e. styles applied from stylesheets).

I've bumped to version 1.5.0 on npm and am about to update the example projects.

from avoriaz.

JeffWeim avatar JeffWeim commented on May 28, 2024

Thank you @eddyerburgh for the quick fix. Very much appreciated.

This is a moot point now, but just FYI. I had tried the fix in the 1.4.0 release, and when I had the style in a <style></style> tag within the .vue file, I was getting expected some HEX value, but actual was rgb(0, 0, 0). When I debugged it appeared that after the insertBefore() method, the element in question only had it's initial CSS properties, black in this case since I was testing color.

Lastly, may I make a suggestion for the new hasStyle test. It looks like when window.getComputedStyle(mockNode)[style] executes, it's using rgb colors only. Could we add an option to convert this to HEX colors? I could make a PR if needed.

from avoriaz.

eddyerburgh avatar eddyerburgh commented on May 28, 2024

@JeffWeim that's expected behavior - and it's why I deprecated!

getComputedStyles returns the resolved values. Setting color: red results in a computed value of color: rgb(255, 0, 0)(in most browsers).

The resolved value of properties with multiple properties, like background: red, adds the default options. So the computed value is rgb(255, 0, 0) none repeat scroll 0% 0% / auto padding-box border-box!

I couldn't think of an easy way to convert the computed value into the value defined inside style tags.

hasStyle is my solution to this problem.

If your class is .color-black {color: black}, and you call .hasClass('color', 'black') on a wrapper of the element with class color-black, the test will pass. Even though under the hood it is comparing the computed value rgb(0,0,0) with rgb(0,0,0).

It can take a CSS color or hex value as input and apply these styles to a temporary node. it then compares the computed value of the temporary node with computed value of the node you are testing on. Under the hood it converts to RGB, but the outcome is still the same.

So I don't think there is any need to convert to hex.

If you do want to contribute though, I want to add support for direct sibling and sibling combinators in the find method 😄 .

from avoriaz.

JeffWeim avatar JeffWeim commented on May 28, 2024

@eddyerburgh Thanks, that explanation makes more sense.

I can take a look and see if I can come up with something!

from avoriaz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.