Comments (6)
Hi thanks for the issue, I'll have a look and try for a fix tomorrow
from avoriaz.
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.
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.
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.
@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.
@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)
- External JS files "not defined" HOT 1
- Can't get input value based on v-model HOT 2
- Migrating from Avoriaz to vue-test-utils HOT 1
- Testing props being passed to child components on mount HOT 2
- Test fails when trying to trigger click inside <router-view></router-view> HOT 1
- hasAttribute docs seem to be outdated HOT 1
- Returning undefined on wrapper.html() for a component with jade and vuex
- Tests disregard disabled attribute HOT 3
- How can I use shallow() for a component wrapped in a function within a class HOT 1
- Trigger not working with click
- Make children select work as it should HOT 1
- data() returns empty object HOT 2
- Trigger mouseover/mouseleave etc
- Is this project deprecated in favor of vue-test-utils now? HOT 2
- Scoped slots (slot-scope) issues HOT 3
- Suppress logged warning on calls to propsData() HOT 1
- vue-test-utils 1.0.0-beta.11 setData Error HOT 1
- vue-test-utils 1.0.0-beta.16 setData Error
- Can't find nested component with neither '.find' nor '.first' wrapper methods HOT 3
- How do you ensure a global is being set to child components from mount? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avoriaz.