Removes code from #constructor to separate functions

This commit is contained in:
Zeno Rocha
2015-09-29 22:14:26 -07:00
parent 3394f59691
commit a5e29bd420
4 changed files with 104 additions and 41 deletions

View File

@@ -19,7 +19,23 @@ describe('ClipboardAction', () => {
document.body.innerHTML = '';
});
describe('#constructor', () => {
describe('#resolveOptions', () => {
it('should set base properties', () => {
let clip = new ClipboardAction({
emitter: new Emitter(),
text: 'foo'
});
assert.property(clip, 'action');
assert.property(clip, 'emitter');
assert.property(clip, 'target');
assert.property(clip, 'text');
assert.property(clip, 'trigger');
assert.property(clip, 'selectedText');
});
});
describe('#initSelection', () => {
it('should throw an error since both "text" and "target" were passed', done => {
try {
new ClipboardAction({

View File

@@ -1,5 +1,6 @@
import Clipboard from '../src/clipboard';
import ClipboardAction from '../src/clipboard-action';
import Delegate from 'delegate-events';
describe('Clipboard', () => {
before(() => {
@@ -18,28 +19,53 @@ describe('Clipboard', () => {
});
describe('#resolveOptions', function() {
before(() => {
global.fn = function() {};
});
it('should set action as a function', () => {
var fn = function() {};
var clipboard = new Clipboard('.btn', {
action: fn
let clipboard = new Clipboard('.btn', {
action: global.fn
});
assert.equal(fn, clipboard.action);
assert.equal(global.fn, clipboard.action);
});
it('should set target as a function', () => {
var fn = function() {};
var clipboard = new Clipboard('.btn', {
target: fn
let clipboard = new Clipboard('.btn', {
target: global.fn
});
assert.equal(fn, clipboard.target);
assert.equal(global.fn, clipboard.target);
});
it('should set text as a function', () => {
var fn = function() {};
var clipboard = new Clipboard('.btn', {
text: fn
let clipboard = new Clipboard('.btn', {
text: global.fn
});
assert.equal(fn, clipboard.text);
assert.equal(global.fn, clipboard.text);
});
});
describe('#delegateClick', function() {
before(() => {
global.spy = sinon.spy(Delegate, 'bind');
});
after(() => {
global.spy.restore();
});
it('should delegate a click event to the passed selector', () => {
let element = document.body;
let selector = '.btn'
let event = 'click';
let clipboard = new Clipboard(selector);
assert.ok(global.spy.calledOnce);
assert.ok(global.spy.calledWith(element, selector, event));
});
});