Skip to content

Commit

Permalink
Initial qunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrasser committed Dec 24, 2013
1 parent 3e95fab commit c0be459
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
1 change: 0 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"expr": true,
"immed": false,
"noarg": true,
"onevar": true,
"smarttabs": true,
"trailing": true,
"unused": true,
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
],
"license": "MIT",
"dependencies": {
"jquery": ">=1.9.0"
"jquery": ">=1.9.0",
"qunit": "~1.12.0"
},
"ignore": [
"**/.*",
Expand Down
2 changes: 1 addition & 1 deletion src/linkified.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Linkified.prototype = {
if (this.element.nodeType === 1) {
Linkified.linkifyNode.call(this, this.element);
} else {
this.element = Linkified.linkify.apply(
this.element = Linkified.linkify.call(
this,
this.element.toString()
);
Expand Down
49 changes: 49 additions & 0 deletions tests/js/linkified.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* global test:true */
/* global equal:true */


test("linkify basics", function () {

var linkifyTests = [{
input: 'google.com',
output: '<a href="http://google.com" class="linkified" target="_blank" >google.com</a>',
options: null
}, {
input: 'I like google.com the most',
output: 'I like <span href="http://google.com" class="linkified" target="_blank" >google.com</span> the most',
options: {
tagName: 'span'
}
}, {
input: 'I like Google.com the most',
output: 'I like Google.com the most',
options: null
}, {
input: 'there are two tests, brennan.com and nick.ca -- do they work?',
output: 'there are two tests, <a href="http://brennan.com" class="linkified alink" target="_parent" >brennan.com</a> and <a href="http://nick.ca" class="linkified alink" target="_parent" >nick.ca</a> -- do they work?',
options: {
linkClass: 'alink',
target: '_parent'
}
}, {
input: 'there are two tests!brennan.com. and nick.ca? -- do they work?',
output: 'there are two tests!<a href="http://brennan.com" class="linkified alink blink" target="_blank" data-link-test="awesome" >brennan.com</a>. and <a href="http://nick.ca" class="linkified alink blink" target="_blank" data-link-test="awesome" >nick.ca</a>? -- do they work?',
options: {
linkClasses: ['alink', 'blink'],
linkAttributes: {
'data-link-test': 'awesome'
}
}
}];

for (var i = 0; i < linkifyTests.length; i++) {
equal(
(new Linkified(
linkifyTests[i].input,
linkifyTests[i].options
)).toString(),
linkifyTests[i].output
);
}

});
18 changes: 18 additions & 0 deletions tests/linkified.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Linkify Basic Tests</title>

<link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
<script src="../bower_components/qunit/qunit/qunit.js"></script>
<script src="../src/linkified.js"></script>

<script src="js/linkified.js"></script>
</head>
<body>

<div id="qunit"></div>

</body>
</html>

0 comments on commit c0be459

Please sign in to comment.