-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "element-query", | ||
"version": "0.0.1", | ||
"description": "JS prollyfill for \"element queries\"", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"mocha": "^2.0.1" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Mr0grog/element-query.git" | ||
}, | ||
"author": "Rob Brackett", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Mr0grog/element-query/issues" | ||
}, | ||
"homepage": "https://github.com/Mr0grog/element-query" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var assert = require("assert"); | ||
|
||
// For now, we need an `elementQuery` object in the global space for the | ||
// parser to attach to. This could probably be done better in the future. | ||
global.elementQuery = { | ||
classNameForRules: function(rules) { | ||
var name = "query"; | ||
for (var i = 0, len = rules.length; i < len; i++) { | ||
name += "_" + rules[i].property + "_" + rules[i].value + rules[i].units; | ||
} | ||
return name; | ||
} | ||
} | ||
require("../lib/parser.js"); | ||
|
||
describe("Parser", function() { | ||
|
||
it("can detect a simple element query", function() { | ||
var result = elementQuery.parser.parseStyleText( | ||
".test-element:media(max-available-width: 30em) { background: purple; }" | ||
); | ||
assert.equal(result.queries.length, 1, "Should have found 1 query."); | ||
assert.equal(result.queries[0].selector, ".test-element", "The selector for the query should be '.test-element'."); | ||
|
||
assert.equal(result.queries[0].rules.length, 1, "There should be one rule in the query."); | ||
assert.equal(result.queries[0].rules[0].property, "max-available-width", "The query should be for 'max-available-width'."); | ||
assert.equal(result.queries[0].rules[0].value, 30, "The query's value should be 30."); | ||
assert.equal(result.queries[0].rules[0].units, "em", "The query's units should be 'em'"); | ||
}); | ||
|
||
}); |