Skip to content

Commit

Permalink
support * selector in subTree
Browse files Browse the repository at this point in the history
  • Loading branch information
glenjamin committed Oct 16, 2015
1 parent c138d20 commit ade38fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions skin-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ function matchComponentType(type, node) {
}

function createNodePredicate(query) {
if (query == '*') {
return alwaysTrue;
}
if (query.match(/^\.[\w\-]+$/)) {
return findNodeByClass(query.substring(1));
}
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ describe("skin-deep", function() {
var abc = tree.subTree("#blah");
expect(abc).to.eql(false);
});
it("should grab a subtree by * selector + props", function() {
var wut = tree.subTree("*", { id: 'wut', prop: "val" });
expect(wut).to.be.an('object');
expect(wut.getRenderOutput().props).to.have.property("id", "wut");
});
it("should grab a subtree by id selector", function() {
var abc = tree.subTree("#abc");
expect(abc).to.be.an('object');
Expand Down Expand Up @@ -536,6 +541,21 @@ describe("skin-deep", function() {
});
});
});
describe("using * selector with props", function() {
beforeEach(function() {
trees = tree.everySubTree("*", { children: 1 });
});
it("should return array", function() {
expect(trees).to.be.an('array');
expect(trees).to.have.length(1);
});
it("should have SkinDeep subtrees in array", function() {
trees.forEach(function(subTree) {
expect(subTree).to.be.an('object');
expect(Object.keys(subTree)).to.eql(Object.keys(tree));
});
});
});
describe("nested matches", function() {
before(function() {
tree = sd.shallowRender(
Expand Down

0 comments on commit ade38fa

Please sign in to comment.