Skip to content

Commit

Permalink
Starter tests for addressing #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr0grog committed Dec 18, 2014
1 parent 1dc4f1b commit c1928a8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
26 changes: 26 additions & 0 deletions package.json
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"
}
31 changes: 31 additions & 0 deletions test/parser.js
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'");
});

});

0 comments on commit c1928a8

Please sign in to comment.