diff --git a/src/mixinResult.js b/src/mixinResult.js index 97ce09a..a3bf820 100644 --- a/src/mixinResult.js +++ b/src/mixinResult.js @@ -123,6 +123,23 @@ MixinResult.prototype = { assert.equal(declarationValue, value.toString(), message); }, + declaresProperties: function(property, value) { + var declarations = parsers.findDeclarations(this.ast, property); + var declarationValues = []; + declarations.forEach(function(declaration){ + declarationValues.push(declaration.value); + }); + var message = 'Value: ' + declarationValues + ' does not equal value: ' + value + '.'; + assert.equal(declarationValues.toString(), value.toString(), message); + }, + + declaresInSelector: function(selector, property, value) { + var declaration = parsers.findDeclarationInSelector(this.ast, selector, property); + var declarationValue = declaration ? utilities.scrubQuotes(declaration.value) : ''; + var message = 'In Selector:'+ selector + ' the value: ' + declarationValue + ' does not equal value: ' + value + '.'; + assert.equal(declarationValue, value.toString(), message); + }, + doesNotDeclare: function(property, value) { var declaration = parsers.findDeclaration(this.ast, property); var declarationValue = declaration ? utilities.scrubQuotes(declaration.value) : ''; diff --git a/src/parsers.js b/src/parsers.js index c88971e..1981a0c 100644 --- a/src/parsers.js +++ b/src/parsers.js @@ -23,7 +23,6 @@ function hasSelectorValue(rule, selectorValue) { function findDeclarationProperty(rule, declarationProperty) { var foundDeclaration; - if (rule.declarations) { rule.declarations.forEach(function(declaration) { if (declaration.property === declarationProperty) { @@ -31,10 +30,21 @@ function findDeclarationProperty(rule, declarationProperty) { } }); } - return foundDeclaration; } +function findDeclarationsProperties(rule, declarationProperty) { + var foundDeclarations = []; + if (rule.declarations) { + rule.declarations.forEach(function(declaration) { + if (declaration.property === declarationProperty) { + foundDeclarations.push(declaration); + } + }); + } + return foundDeclarations; +} + function isFontFace(rule) { if (rule.type === 'font-face') { return true; @@ -57,10 +67,8 @@ var Parsers = { }); return count; }, - findDeclaration: function(ast, property) { var found; - ast.stylesheet.rules.forEach(function(rule) { if (rule.type === 'media') { rule.rules.forEach(function(rule) { @@ -74,6 +82,39 @@ var Parsers = { return found; }, + findDeclarations: function(ast, property) { + var found; + ast.stylesheet.rules.forEach(function(rule) { + if (rule.type === 'media') { + rule.rules.forEach(function(rule) { + found = found || findDeclarationsProperties(rule, property); + }); + } else { + found = found || findDeclarationsProperties(rule, property); + } + }); + + return found; + }, + + findDeclarationInSelector: function(ast, selector, property) { + var found; + if (selector.indexOf("&") > -1) { + selector = selector.replace("&", ".test"); + } + if (selector.indexOf("@at-root") > -1) { + selector = selector.replace("@at-root ", ""); + } + ast.stylesheet.rules.forEach(function(rule) { + for(var i = 0; i < rule.selectors.length; i++) { + if(rule.selectors[i].indexOf(selector) >= 0 ) { + found = found || findDeclarationProperty(rule, property); + } + } + }); + return found; + }, + findMedia: function(ast) { var found = [];