Adds tests for constructor

This commit is contained in:
Zeno Rocha 2015-09-20 00:57:19 -07:00
parent b1d0ac9520
commit ec20389775
3 changed files with 45 additions and 1 deletions

View File

@ -14,6 +14,7 @@
"devDependencies": {
"babelify": "^6.3.0",
"browserify": "^11.1.0",
"chai": "^3.2.0",
"mocha": "^2.3.2",
"uglify": "^0.1.5"
},

View File

@ -1,3 +1,28 @@
describe('Clipboard', () => {
var assert = chai.assert;
describe('Clipboard', () => {
describe('#constructor', () => {
it('should throw an error since there was no arguments passed', done => {
try {
new Clipboard();
}
catch(e) {
done();
}
});
it('should throw an error since an empty selector has been passed', done => {
try {
new Clipboard('#abc');
}
catch(e) {
done();
}
});
it('should create a NodeList and store it in a property', () => {
let clipboard = new Clipboard('.btn');
return assert.instanceOf(clipboard.triggers, NodeList);
});
});
});

View File

@ -7,8 +7,26 @@
<body>
<div id="mocha"></div>
<div>
<p>Copy text from attribute</p>
<button class="btn" data-action="copy" data-text="hello">Copy</button>
</div>
<div>
<p>Copy text from another element</p>
<input id="foo" type="text" value="hello">
<button class="btn" data-action="copy" data-target="foo">Copy</button>
</div>
<div>
<p>Cut text from another element</p>
<textarea id="bar">hello</textarea>
<button class="btn" data-action="cut" data-target="bar">Cut</button>
</div>
<script src="../dist/clipboard.min.js"></script>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<script src="clipboard.js"></script>