Skip to content

Commit

Permalink
fix(api): fix binds tree for import API
Browse files Browse the repository at this point in the history
  • Loading branch information
voischev committed Jan 8, 2016
1 parent 52bfcad commit a8f2500
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/api.js
Expand Up @@ -47,12 +47,12 @@ export default {
* }
*/
match(expression, cb) {
return Array.isArray(expression) ? this.walk(node => {
return Array.isArray(expression) ? traverse(this, node => {
for (let i = 0, len = expression.length; i < len; i++) {
if (compare(expression[i], node)) return cb(node);
}
return node;
}) : this.walk(node => {
}) : traverse(this, node => {
if (compare(expression, node)) return cb(node);
return node;
});
Expand Down
15 changes: 15 additions & 0 deletions test/api.js
@@ -1,6 +1,7 @@
/* jshint mocha: true, maxlen: false */
import posthtml from '../index.js';
import { expect } from 'chai';
import { walk, match } from '../lib/api';

function test(nodes, referense, fn, options, done) {
expect(posthtml([].concat(fn))
Expand Down Expand Up @@ -186,4 +187,18 @@ describe('API', () => {
});
});

describe('import API', () => {
it('walk', () => {
let tree = ['test', { tag: 'a', content: ['find'] }, { tag: 'a' }];
walk.bind(tree)(() => 'a');
expect(['a', 'a', 'a']).to.eql(tree);
});

it('match', () => {
let tree = [{ tag: 'a', content: ['find'] }, { tag: 'a' }];
match.bind(tree)({ tag: 'a', content: true }, () => 'a');
expect(['a', { tag: 'a' }]).to.eql(tree);
});
});

});

0 comments on commit a8f2500

Please sign in to comment.