Comments (7)
Here is how I added it to my Rails Asset Pipeline:
# =require ./jasmine-jquery
jasmine.JQuery.matchersClass.toHaveCss = (css)->
(return false unless @actual.css(prop) is value) for prop, value of css
true
from jasmine-jquery.
Yeah I've been meaning to do this actually, will do it by the end of today for sure.
from jasmine-jquery.
When you check colors not all browsers return the same values, i had to use this
jasmine.JQuery.matchersClass.toHaveCss = function( css ) {
var colorToHex = function( color ) {
if ( color.substr(0, 1) === '#' ) {
return color;
}
var digits = /(.*?)rgb\((\d+), (\d+), (\d+)\)/.exec(color);
var red = parseInt(digits[2]);
var green = parseInt(digits[3]);
var blue = parseInt(digits[4]);
var rgb = blue | (green << 8) | (red << 16);
return digits[1] + '#' + rgb.toString(16);
};
var convertToHexIfRgb = function( value_to_check ) {
if( value_to_check.substr(0, 4) === 'rgb(' ) {
return colorToHex( value_to_check );
}
return value_to_check;
};
for( var prop in css ) {
var actual_prop = convertToHexIfRgb( this.actual.css( prop ) ).toUpperCase();
var expected_prop = convertToHexIfRgb( css[prop] ).toUpperCase();
if( actual_prop !== expected_prop ) {
return false;
}
}
return true;
}
To get things working
from jasmine-jquery.
With regards to color, that is true. Usually what I do is something like:
blue = $('<div style="color: blue"/>').css 'color' # or something similar using some existing element as reference...
expect(someElement).toHaveCss color: blue
from jasmine-jquery.
different browsers are not consistent on how to return colors but they always return it in the same representation :)
from jasmine-jquery.
I've pushed a simple solution, didn't want to introduce something so complex initially, @nicoladj77 make a separate ticket on handling colors and we can discuss.
Thanks.
from jasmine-jquery.
Thank you, @travisjeffery :)
from jasmine-jquery.
Related Issues (20)
- Why is not recognizing jQuery object HOT 1
- Cache for fixtures is based on relative paths not absolute
- Feature Request: .toHaveMinLength()
- Documentation about jQuery 3 HOT 5
- toBeEmpty() matcher inconsistent behavior
- Error during loading: Cannot set property 'spiedEventsKey' of undefined HOT 3
- HTML fixtures load but JSON fixtures do not HOT 2
- Is it possible to loadFixtures over http? HOT 1
- Readme for toBeInDom() is incorrect
- Bug in addCustomEqualityTester HOT 2
- How to check whether the jquery plugin is applied to the DOM element? HOT 2
- Issue in jquery bower version
- Mocking with jasmine-ajax has been fixed
- Updating the documentation to include `npm install jasmine-jquery --save`
- laravel when saving sass giving error "Cannot set property '__file' of undefined" but working when saving js ..... every time mix build successful HOT 2
- JQUERY PHP (XHR LOADING FAILED)
- Is this library still maintained? HOT 10
- Can't set lang attribute on element HOT 1
- Has anyone ever tried to use this with Jest? HOT 2
- critical security issue in 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 jasmine-jquery.