vant/test/unit/specs/utils.dom.spec.js
张敏 dd5e2eefa9 添加单元测试 (#12)
* 添加单元测试
2017-04-25 19:57:17 +08:00

32 lines
852 B
JavaScript

import { hasClass, addClass, removeClass } from 'src/utils/dom';
describe('Utils Dom', () => {
let wrapper;
beforeEach(() => {
wrapper = document.createElement('div');
wrapper.classList.add('test-class');
document.body.appendChild(wrapper);
});
afterEach(() => {
document.body.removeChild(wrapper);
});
it('hasClass', () => {
expect(hasClass(wrapper, 'test-class')).to.be.true;
expect(hasClass()).to.be.false;
});
it('addClass and removeClass', () => {
expect(hasClass(wrapper, 'test-class')).to.be.true;
addClass(wrapper, ' other-class');
expect(hasClass(wrapper, 'other-class')).to.be.true;
expect(addClass()).to.equal(undefined);
removeClass(wrapper, ' other-class');
expect(hasClass(wrapper, 'other-class')).to.be.false;
expect(removeClass()).to.equal(undefined);
});
});