mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[Improvement] add utils test cases (#380)
This commit is contained in:
parent
5a17bc520a
commit
df835618b0
@ -19,9 +19,10 @@ export function get(object, path) {
|
|||||||
|
|
||||||
const camelizeRE = /-(\w)/g;
|
const camelizeRE = /-(\w)/g;
|
||||||
export function camelize(str) {
|
export function camelize(str) {
|
||||||
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '');
|
return str.replace(camelizeRE, (_, c) => c.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isAndroid() {
|
export function isAndroid() {
|
||||||
|
/* istanbul ignore next */
|
||||||
return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
|
return isServer ? false : /android/.test(navigator.userAgent.toLowerCase());
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
import { isServer } from './index';
|
import { isServer } from './index';
|
||||||
|
|
||||||
let prev = Date.now();
|
let prev = Date.now();
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
function fallback(fn) {
|
function fallback(fn) {
|
||||||
const curr = Date.now();
|
const curr = Date.now();
|
||||||
const ms = Math.max(0, 16 - (curr - prev));
|
const ms = Math.max(0, 16 - (curr - prev));
|
||||||
@ -13,11 +15,16 @@ function fallback(fn) {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
const global = isServer ? global : window;
|
const global = isServer ? global : window;
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
const iRaf =
|
const iRaf =
|
||||||
global.requestAnimationFrame ||
|
global.requestAnimationFrame ||
|
||||||
global.webkitRequestAnimationFrame ||
|
global.webkitRequestAnimationFrame ||
|
||||||
fallback;
|
fallback;
|
||||||
|
|
||||||
|
/* istanbul ignore next */
|
||||||
const iCancel =
|
const iCancel =
|
||||||
global.cancelAnimationFrame ||
|
global.cancelAnimationFrame ||
|
||||||
global.webkitCancelAnimationFrame ||
|
global.webkitCancelAnimationFrame ||
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import Area from 'packages/area';
|
import Area from 'packages/area';
|
||||||
import { mount } from 'avoriaz';
|
import { mount } from 'avoriaz';
|
||||||
import AreaList from '../mock/area.json';
|
import AreaList from '../mock/area.json';
|
||||||
import { setTimeout } from 'timers';
|
|
||||||
|
|
||||||
describe('Area', () => {
|
describe('Area', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
@ -27,8 +26,6 @@ describe('Area', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-area')).to.be.true;
|
|
||||||
|
|
||||||
const confirmBtn = wrapper.find('.van-picker__confirm')[0];
|
const confirmBtn = wrapper.find('.van-picker__confirm')[0];
|
||||||
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
|
||||||
@ -49,7 +46,6 @@ describe('Area', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-area')).to.be.true;
|
|
||||||
expect(wrapper.vm.$refs.picker.getColumnValue(2).code).to.equal('110101');
|
expect(wrapper.vm.$refs.picker.getColumnValue(2).code).to.equal('110101');
|
||||||
|
|
||||||
wrapper.setProps({
|
wrapper.setProps({
|
||||||
@ -68,9 +64,7 @@ describe('Area', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-area')).to.be.true;
|
|
||||||
expect(wrapper.vm.areaColumns.length).to.equal(0);
|
expect(wrapper.vm.areaColumns.length).to.equal(0);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('create an area with columnsNum equal 2', () => {
|
it('create an area with columnsNum equal 2', () => {
|
||||||
@ -81,7 +75,6 @@ describe('Area', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-area')).to.be.true;
|
|
||||||
expect(wrapper.vm.areaColumns.length).to.equal(2);
|
expect(wrapper.vm.areaColumns.length).to.equal(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -93,7 +86,6 @@ describe('Area', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-area')).to.be.true;
|
|
||||||
expect(wrapper.vm.areaColumns.length).to.equal(1);
|
expect(wrapper.vm.areaColumns.length).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,7 +96,6 @@ describe('Area', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.hasClass('van-area')).to.be.true;
|
|
||||||
const cancelBtn = wrapper.find('.van-picker__cancel')[0];
|
const cancelBtn = wrapper.find('.van-picker__cancel')[0];
|
||||||
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
|
||||||
@ -115,4 +106,23 @@ describe('Area', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('onChange method', () => {
|
||||||
|
wrapper = mount(Area, {
|
||||||
|
propsData: {
|
||||||
|
areaList: AreaList
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let list = [];
|
||||||
|
const setColumnValues = (index, arr) => {
|
||||||
|
list = [...list, ...arr];
|
||||||
|
};
|
||||||
|
const code = { code: '110101' };
|
||||||
|
|
||||||
|
wrapper.vm.onChange({ setColumnValues }, [code], 0);
|
||||||
|
wrapper.vm.onChange({ setColumnValues }, [code, code], 1);
|
||||||
|
|
||||||
|
expect(list.length).to.equal(33);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -3,17 +3,23 @@ import PickerColumn from 'packages/picker/PickerColumn';
|
|||||||
import { mount } from 'avoriaz';
|
import { mount } from 'avoriaz';
|
||||||
import { dragHelper } from '../utils';
|
import { dragHelper } from '../utils';
|
||||||
|
|
||||||
const pickerColumns = [
|
const simpleColumn = ['1990', '1991', '1992', '1993', '1994', '1995'];
|
||||||
|
const columns = [
|
||||||
{
|
{
|
||||||
values: ['vip', 'normal'],
|
values: ['vip', 'normal'],
|
||||||
className: 'column1'
|
className: 'column1'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
values: ['1990', '1991', '1992', '1993', '1994', '1995'],
|
values: simpleColumn,
|
||||||
className: 'column2'
|
className: 'column2'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const disabledOption = [{
|
||||||
|
disabled: true,
|
||||||
|
text: '123'
|
||||||
|
}];
|
||||||
|
|
||||||
describe('Picker', () => {
|
describe('Picker', () => {
|
||||||
let wrapper;
|
let wrapper;
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@ -23,7 +29,7 @@ describe('Picker', () => {
|
|||||||
it('create picker', () => {
|
it('create picker', () => {
|
||||||
wrapper = mount(Picker, {
|
wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
columns: pickerColumns
|
columns: columns
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,7 +42,7 @@ describe('Picker', () => {
|
|||||||
it('set picker values', () => {
|
it('set picker values', () => {
|
||||||
wrapper = mount(Picker, {
|
wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
columns: pickerColumns
|
columns: columns
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -63,6 +69,7 @@ describe('Picker', () => {
|
|||||||
expect(wrapper.vm.getColumnIndex(0)).to.equal(0);
|
expect(wrapper.vm.getColumnIndex(0)).to.equal(0);
|
||||||
expect(wrapper.vm.getColumnIndex(1)).to.equal(2);
|
expect(wrapper.vm.getColumnIndex(1)).to.equal(2);
|
||||||
expect(wrapper.vm.getColumnIndex(2)).to.equal(undefined);
|
expect(wrapper.vm.getColumnIndex(2)).to.equal(undefined);
|
||||||
|
expect(wrapper.vm.getIndexes(2)).to.eql([0, 2]);
|
||||||
|
|
||||||
wrapper.vm.setIndexes([1, 4]);
|
wrapper.vm.setIndexes([1, 4]);
|
||||||
expect(wrapper.vm.getColumnValue(0)).to.equal('normal');
|
expect(wrapper.vm.getColumnValue(0)).to.equal('normal');
|
||||||
@ -70,7 +77,7 @@ describe('Picker', () => {
|
|||||||
expect(wrapper.vm.getColumnValue(2)).to.equal(undefined);
|
expect(wrapper.vm.getColumnValue(2)).to.equal(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('create a invalid columns picker', () => {
|
it('create a simple column picker', () => {
|
||||||
wrapper = mount(Picker, {
|
wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
columns: undefined
|
columns: undefined
|
||||||
@ -81,10 +88,20 @@ describe('Picker', () => {
|
|||||||
expect(wrapper.vm.currentColumns.length).to.equal(0);
|
expect(wrapper.vm.currentColumns.length).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('create a invalid columns picker', () => {
|
||||||
|
wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
columns: simpleColumn
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.vm.isSimpleColumn).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
it('set invalid index columns', () => {
|
it('set invalid index columns', () => {
|
||||||
wrapper = mount(Picker, {
|
wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
columns: pickerColumns
|
columns: columns
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -100,7 +117,7 @@ describe('Picker', () => {
|
|||||||
it('emit a change event when column change', (done) => {
|
it('emit a change event when column change', (done) => {
|
||||||
wrapper = mount(Picker, {
|
wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
columns: pickerColumns
|
columns: columns
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -113,6 +130,22 @@ describe('Picker', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('simple column emit a change event when column change', (done) => {
|
||||||
|
wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
columns: simpleColumn
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
wrapper.vm.setColumnValue(0, '1993');
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(eventStub.calledOnce).to.be.true;
|
||||||
|
expect(eventStub.calledWith('change'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('create a empty picker and emit a cencel event', (done) => {
|
it('create a empty picker and emit a cencel event', (done) => {
|
||||||
wrapper = mount(Picker, {
|
wrapper = mount(Picker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
@ -155,6 +188,25 @@ describe('Picker', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('simple column emit a confirm event', (done) => {
|
||||||
|
wrapper = mount(Picker, {
|
||||||
|
propsData: {
|
||||||
|
columns: simpleColumn,
|
||||||
|
showToolbar: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const eventStub = sinon.stub(wrapper.vm, '$emit');
|
||||||
|
const cancelBtn = wrapper.find('.van-picker__confirm')[0];
|
||||||
|
cancelBtn.trigger('click');
|
||||||
|
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(eventStub.calledOnce).to.be.true;
|
||||||
|
expect(eventStub.calledWith('confirm'));
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('PickerColumn', () => {
|
describe('PickerColumn', () => {
|
||||||
@ -199,6 +251,22 @@ describe('PickerColumn', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('change defaultIndex', (done) => {
|
||||||
|
wrapper = mount(PickerColumn, {
|
||||||
|
propsData: {
|
||||||
|
options: simpleColumn,
|
||||||
|
defaultIndex: 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.vm.currentIndex).to.equal(0);
|
||||||
|
wrapper.vm.defaultIndex = 2;
|
||||||
|
wrapper.vm.$nextTick(() => {
|
||||||
|
expect(wrapper.vm.currentIndex).to.equal(2);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('select disabled options', () => {
|
it('select disabled options', () => {
|
||||||
wrapper = mount(PickerColumn, {
|
wrapper = mount(PickerColumn, {
|
||||||
propsData: {
|
propsData: {
|
||||||
@ -217,10 +285,21 @@ describe('PickerColumn', () => {
|
|||||||
expect(wrapper.vm.currentIndex).to.equal(1);
|
expect(wrapper.vm.currentIndex).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('disabled options', () => {
|
||||||
|
wrapper = mount(PickerColumn, {
|
||||||
|
propsData: {
|
||||||
|
options: disabledOption
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('.van-picker-column--disabled').length).to.equal(1);
|
||||||
|
expect(wrapper.vm.currentIndex).to.equal(undefined);
|
||||||
|
});
|
||||||
|
|
||||||
it('drag options', () => {
|
it('drag options', () => {
|
||||||
wrapper = mount(PickerColumn, {
|
wrapper = mount(PickerColumn, {
|
||||||
propsData: {
|
propsData: {
|
||||||
options: pickerColumns[1].values
|
options: columns[1].values
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
expect(wrapper.vm.currentIndex).to.equal(0);
|
expect(wrapper.vm.currentIndex).to.equal(0);
|
||||||
|
@ -64,7 +64,7 @@ describe('SubmitBar', () => {
|
|||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can not submit when disabled', () => {
|
it('can not submit when disabled', (done) => {
|
||||||
wrapper = mount(SubmitBar, {
|
wrapper = mount(SubmitBar, {
|
||||||
propsData: {
|
propsData: {
|
||||||
disabled: true,
|
disabled: true,
|
||||||
@ -77,10 +77,11 @@ describe('SubmitBar', () => {
|
|||||||
wrapper.find('.van-button')[0].trigger('click');
|
wrapper.find('.van-button')[0].trigger('click');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(submitSpyFunc.calledOnce).to.be.false;
|
expect(submitSpyFunc.calledOnce).to.be.false;
|
||||||
|
done();
|
||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can not submit when loading', () => {
|
it('can not submit when loading', (done) => {
|
||||||
wrapper = mount(SubmitBar, {
|
wrapper = mount(SubmitBar, {
|
||||||
propsData: {
|
propsData: {
|
||||||
loading: true,
|
loading: true,
|
||||||
@ -93,6 +94,7 @@ describe('SubmitBar', () => {
|
|||||||
wrapper.find('.van-button')[0].trigger('click');
|
wrapper.find('.van-button')[0].trigger('click');
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(submitSpyFunc.calledOnce).to.be.false;
|
expect(submitSpyFunc.calledOnce).to.be.false;
|
||||||
|
done();
|
||||||
}, 300);
|
}, 300);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -95,7 +95,7 @@ describe('Tabs', () => {
|
|||||||
active: 7
|
active: 7
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapper.vm.$nextTick(() => {
|
wrapper.vm.$nextTick(() => {
|
||||||
const nTab = wrapper.find('.van-tab')[6];
|
const nTab = wrapper.find('.van-tab')[6];
|
||||||
nTab.trigger('click');
|
nTab.trigger('click');
|
||||||
@ -103,50 +103,6 @@ describe('Tabs', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('test swipe', (done) => {
|
|
||||||
wrapper = mount(MoreTabsTestComponent, {
|
|
||||||
attachToDocument: true
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
const nSwipe = wrapper.find('.van-tabs__swipe')[0];
|
|
||||||
|
|
||||||
const eventMouseObject = new window.Event('mousedown');
|
|
||||||
eventMouseObject.pageX = 200;
|
|
||||||
nSwipe.element.dispatchEvent(eventMouseObject);
|
|
||||||
|
|
||||||
const eventTouchObject = new window.Event('touchstart');
|
|
||||||
eventTouchObject.changedTouches = [{ pageX: 200 }];
|
|
||||||
nSwipe.element.dispatchEvent(eventTouchObject);
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
const nSwipe = wrapper.find('.van-tabs__swipe')[0];
|
|
||||||
|
|
||||||
const eventMouseMoveObject = new window.Event('mousemove');
|
|
||||||
eventMouseMoveObject.pageX = 0;
|
|
||||||
document.dispatchEvent(eventMouseMoveObject);
|
|
||||||
|
|
||||||
const eventObject = new window.Event('touchmove');
|
|
||||||
eventObject.changedTouches = [{ pageX: 0 }];
|
|
||||||
nSwipe.element.dispatchEvent(eventObject);
|
|
||||||
|
|
||||||
// 结束滑动
|
|
||||||
const eventMouseUpObject = new window.Event('mouseup');
|
|
||||||
document.dispatchEvent(eventMouseUpObject);
|
|
||||||
const eventEndObject = new window.Event('touchend');
|
|
||||||
eventEndObject.changedTouches = [{}];
|
|
||||||
nSwipe.element.dispatchEvent(eventEndObject);
|
|
||||||
}, 1000);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
const nItem = wrapper.find('.van-tab')[0];
|
|
||||||
expect(nItem.hasClass('van-tab--active')).to.be.true;
|
|
||||||
|
|
||||||
done();
|
|
||||||
}, 1200);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('watch tab props changes', (done) => {
|
it('watch tab props changes', (done) => {
|
||||||
wrapper = mount(TabsTestComponent);
|
wrapper = mount(TabsTestComponent);
|
||||||
wrapper.vm.firstTabTitle = '测试标题';
|
wrapper.vm.firstTabTitle = '测试标题';
|
||||||
|
@ -89,7 +89,7 @@ describe('Toast', () => {
|
|||||||
it('toast disappeared after duration', (done) => {
|
it('toast disappeared after duration', (done) => {
|
||||||
Toast({
|
Toast({
|
||||||
message: 'toast',
|
message: 'toast',
|
||||||
duration: 100
|
duration: 10
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(document.querySelector('.van-toast-wrapper').style.display === 'none').to.be.false;
|
expect(document.querySelector('.van-toast-wrapper').style.display === 'none').to.be.false;
|
||||||
@ -97,7 +97,7 @@ describe('Toast', () => {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
expect(document.querySelector('.van-toast-wrapper').style.display === 'none').to.be.true;
|
expect(document.querySelector('.van-toast-wrapper').style.display === 'none').to.be.true;
|
||||||
done();
|
done();
|
||||||
}, 500);
|
}, 300);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toast duration 0', (done) => {
|
it('toast duration 0', (done) => {
|
||||||
|
@ -93,4 +93,16 @@ describe('Uploader', () => {
|
|||||||
expect(wrapper.contains('input')).to.equal(true);
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
|
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('unknown resultType', () => {
|
||||||
|
wrapper = mount(Uploader, {
|
||||||
|
propsData: {
|
||||||
|
disabled: false,
|
||||||
|
resultType: 'xxxx'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.contains('input')).to.equal(true);
|
||||||
|
expect(wrapper.vm.onValueChange({ target: { files: [new File([], '/Users')] }})).to.equal(undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
57
test/unit/specs/utils.spec.js
Normal file
57
test/unit/specs/utils.spec.js
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import deepClone from 'packages/utils/deep-clone';
|
||||||
|
import { isAndroid, isDef, camelize, get } from 'packages/utils';
|
||||||
|
import { raf, cancel } from 'packages/utils/raf';
|
||||||
|
|
||||||
|
describe('Utils', () => {
|
||||||
|
it('deepClone', () => {
|
||||||
|
const a = { foo: 0 };
|
||||||
|
const b = { foo: 0, bar: 1 };
|
||||||
|
const fn = () => {};
|
||||||
|
const arr = [a, b];
|
||||||
|
expect(deepClone(a)).to.eql(a);
|
||||||
|
expect(deepClone(b)).to.eql(b);
|
||||||
|
expect(deepClone(fn)).to.eql(fn);
|
||||||
|
expect(deepClone(arr)).to.eql(arr);
|
||||||
|
expect(deepClone(undefined)).to.eql(undefined);
|
||||||
|
expect(deepClone(1)).to.eql(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isDef', () => {
|
||||||
|
expect(isDef(null)).to.be.false;
|
||||||
|
expect(isDef(undefined)).to.be.false;
|
||||||
|
expect(isDef(1)).to.be.true;
|
||||||
|
expect(isDef('1')).to.be.true;
|
||||||
|
expect(isDef({})).to.be.true;
|
||||||
|
expect(isDef(() => {})).to.be.true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('camelize', () => {
|
||||||
|
expect(camelize('ab')).to.equal('ab');
|
||||||
|
expect(camelize('a-b')).to.equal('aB');
|
||||||
|
expect(camelize('a-b-c-d')).to.equal('aBCD');
|
||||||
|
expect(camelize('a-b-')).to.equal('aB-');
|
||||||
|
expect(camelize('-a-b')).to.equal('AB');
|
||||||
|
expect(camelize('-')).to.equal('-');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('get', () => {
|
||||||
|
expect(get({ a: 1 }, 'a')).to.equal(1);
|
||||||
|
expect(get({ a: { b: 2 }}, 'a.b')).to.equal(2);
|
||||||
|
expect(get({ a: { b: 2 }}, 'a.b.c')).to.equal('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('isAndroid', () => {
|
||||||
|
expect(isAndroid()).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('raf', (done) => {
|
||||||
|
const spy = sinon.spy();
|
||||||
|
raf(spy);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
expect(spy.calledOnce).to.be.true;
|
||||||
|
cancel(1);
|
||||||
|
done();
|
||||||
|
}, 50);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user