Skip to content

Commit

Permalink
Adding tests for wiring.append, appendToFile, prepend, prependToFile,…
Browse files Browse the repository at this point in the history
… domUpdate
  • Loading branch information
timrwood committed Oct 16, 2013
1 parent 4717c0d commit 65e145a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/fixtures/append-prepend-to-file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body><section><span></span></section></body></html>
58 changes: 58 additions & 0 deletions test/wiring.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,62 @@ describe('yeoman.generator.lib.actions.wiring', function () {

assert.equal(res, res2);
});

it('should append content in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section><span></span>TEST</section></body></html>';
assert.equal(wiring.append(html, 'section', 'TEST'), expected);
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'a'), expected);
});

it('should prepend content in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section>TEST<span></span></section></body></html>';
assert.equal(wiring.prepend(html, 'section', 'TEST'), expected);
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'p'), expected);
});

it('should replace content correctly', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section>TEST</section></body></html>';
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'r'), expected);
});

it('should delete content correctly', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body></body></html>';
assert.equal(wiring.domUpdate(html, 'section', 'TEST', 'd'), expected);
});

it('should append to files in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section><span></span>TEST</section></body></html>';
var filepath = path.join(this.fixtures, 'append-prepend-to-file.html');

fs.writeFileSync(filepath, html, 'utf-8');

wiring.appendToFile(filepath, 'section', 'TEST');

var actual = fs.readFileSync(filepath, 'utf-8').trim();

assert.equal(actual, expected);

fs.writeFileSync(filepath, html, 'utf-8');
});

it('should prepend to files in the right place', function () {
var html = '<html><body><section><span></span></section></body></html>';
var expected = '<html><body><section>TEST<span></span></section></body></html>';
var filepath = path.join(this.fixtures, 'append-prepend-to-file.html');

fs.writeFileSync(filepath, html, 'utf-8');

wiring.prependToFile(filepath, 'section', 'TEST');

var actual = fs.readFileSync(filepath, 'utf-8').trim();

assert.equal(actual, expected);

fs.writeFileSync(filepath, html, 'utf-8');
});
});

0 comments on commit 65e145a

Please sign in to comment.