From 34a30c1b2576632d0300bc8aef5b06b535423063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=8D=E7=AB=AF=E5=B0=8F=E6=AD=A6?= Date: Sat, 16 Sep 2017 12:38:33 -0500 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=20laydate=20=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20(#61)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加 laydate 测试 * 添加 options.format 和 options.value 叠加时的验证 * 修改必须单元测试通过后再进行浏览器测试 * 添加判断css是否加载成功 * 优化 options.elem 测试 * 完善laydate测试 * 更新事件回调测试 * 先把 options.format 注释了, 依赖 master 的修复 * 添加 mock server * 更新404地址 * 使用 show api 来显示日历 * 测试火狐浏览器 * 修复火狐报错 * add callback test case * fix firefox error * fix win var * add window.lay test case * fix firefox test error * add edga test * update `laydate.render({value})` test case * update options.dateTime test case --- .travis.yml | 3 +- karma.conf.base.js | 45 +- karma.conf.sauce.js | 7 + src/lay/modules/laydate.js | 2 +- test/lay/modules/laydate.js | 1571 +++++++++++++++++++++++++++++++---- test/layui.js | 2 +- 6 files changed, 1479 insertions(+), 151 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef79766..817d5a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,6 @@ cache: directories: - node_modules script: - - npm run test:cov - - npm run test:sauce + - npm run test:cov && npm run test:sauce after_script: - npm install coveralls && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage diff --git a/karma.conf.base.js b/karma.conf.base.js index f60096f..9ec2d42 100644 --- a/karma.conf.base.js +++ b/karma.conf.base.js @@ -3,6 +3,36 @@ * @author fe.xiaowu@gmail.com */ +var url = require('url'); + +/** + * mock一个server供测试使用 + * + * @param {Object} req request + * @param {Object} res response + * @param {Function} next 下一路由 + * + * @example + * 请求 /api/mock 参数如: + * timeout - 超时时间, 默认 0 + * statusCode - 状态码, 默认 200 + * response - 响应内容, 默认 {} + * dataType - 响应格式, 默认 json + */ +var httpServer = function (req, res, next) { + if (req.url.indexOf('/api/mock') === -1) { + return next(); + } + + var data = url.parse(req.url, true).query; + + setTimeout(function () { + res.statusCode = data.statusCode || 200; + res.setHeader('content-type', data.contentType || 'json'); + res.end(data.response || '{}'); + }, data.timeout || 0); +}; + /** * 源文件 * @@ -47,9 +77,6 @@ module.exports = function (config) { // base path that will be used to resolve all patterns (eg. files, exclude) basePath: '', - // Important: 所有插件必须在此声明 - plugins: ['karma-*'], - // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter // Important: 下列数组中文件将『逆序载入』 @@ -136,6 +163,16 @@ module.exports = function (config) { // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits // 脚本调用请设为 true - singleRun: true + singleRun: true, + + middleware: ['httpServer'], + + plugins: ['karma-*', { + 'middleware:httpServer': [ + 'factory', function () { + return httpServer; + } + ] + }] }; }; diff --git a/karma.conf.sauce.js b/karma.conf.sauce.js index 10aed8e..3986143 100644 --- a/karma.conf.sauce.js +++ b/karma.conf.sauce.js @@ -59,6 +59,13 @@ var customLaunchers = { version: '11' }, + sl_edga: { + base: 'SauceLabs', + browserName: 'microsoftedge', + platform: 'Windows 10', + version: '15' + }, + sl_firefox: { base: 'SauceLabs', browserName: 'firefox', diff --git a/src/lay/modules/laydate.js b/src/lay/modules/laydate.js index 40026e7..0cbf40c 100644 --- a/src/lay/modules/laydate.js +++ b/src/lay/modules/laydate.js @@ -162,7 +162,7 @@ //中止冒泡 lay.stope = function(e){ - e = e || win.event; + e = e || window.event; e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; diff --git a/test/lay/modules/laydate.js b/test/lay/modules/laydate.js index cf2d978..fd119ae 100644 --- a/test/lay/modules/laydate.js +++ b/test/lay/modules/laydate.js @@ -8,10 +8,21 @@ var $ = layui.$; var laydate = layui.laydate; +var lay = window.lay; + +/** + * 是否基于`phantomjs`测试, 因为有些特殊的case在ie中是不可用的, 比如: `window.event = {}` + * + * @const + * @type {boolean} + */ +var IS_PHANTOMJS = layui.device('phantomjs').phantomjs; /** * 创建dom元素, 并返回 jquery 对象 * + * @inner + * * @param {string} html 标签 * * @return {jQuery} @@ -20,9 +31,12 @@ var createNode = function (html) { return $(html).addClass('test-node').appendTo('body'); }; + /** * 日期格式化 * + * @inner + * * @param {string} str 格式 * @param {Date|number|string} date 时间对象或者时间缀 * @return {string} @@ -37,8 +51,15 @@ var createNode = function (html) { var dateFormat = function (str, date) { str = str || 'yyyy-MM-dd HH:mm'; - if (date && !(date instanceof Date)) { + if (date) { + if ('number' === typeof date && String(date).length !== 13) { + var temp = new Date(); + temp.setDate(temp.getDate() + date); + date = temp; + } + else if (!(date instanceof Date)) { date = new Date(date); + } } else { date = new Date(); @@ -71,7 +92,6 @@ var dateFormat = function (str, date) { return str; }; - describe('laydate', function () { // 输出测试节点 beforeEach(function () { @@ -89,8 +109,16 @@ describe('laydate', function () { expect(laydate.v).to.not.be.empty; }); - describe('laydate.render()', function () { + it('loaded css link', function () { + // 验证页面元素 + expect($('#layuicss-laydate').length).to.equal(1, '加载laydate.css的link标签必须存在'); + expect($('#layuicss-laydate').css('display')).to.equal('none', '验证laydate.css是否生效'); + // 验证一个不存在的元素 + expect($('#layuicss-laydate-no-suceess').css('display')).to.be.undefined; + }); + + describe('laydate.render()', function () { it('check params and return value', function () { expect(laydate.render()).to.be.a('object', 'render() 返回值必须是对象'); expect(laydate.render('str')).to.have.property('hint'); @@ -98,68 +126,41 @@ describe('laydate', function () { expect(laydate.render({})).to.have.property('config'); }); - describe('options.ready', function () { - it('not elem', function (done) { - var flag = true; - laydate.render({ - ready: function () { - flag = false; - } - }); + describe('options.elem', function () { + it('selector', function () { + expect(function () { + laydate.render({ + elem: '#test-div' + }); - setTimeout(function () { - expect(flag).to.be.true; - done(); - }, 360); + laydate.render({ + elem: '#test-div-layui' + }); + + laydate.render({ + elem: '.ok-layui' + }); + }).to.not.throw; + + expect($('.layui-laydate').length).to.equal(0); }); - it('trigger', function (done) { - laydate.render({ - elem: '#test-div', - ready: function (data) { - expect(data).to.be.a('object'); - done(); - } - }); + it('error selector', function () { + expect(function () { + laydate.render({ + elem: '#test-div-no-selector', + show: true + }); - $('#test-div').click(); + laydate.render({ + elem: '.test-div-no-selector', + show: true + }); + + }).to.not.throw; + + expect($('.layui-laydate').length).to.equal(0); }); - - // 如果是div则自动切换成click - it('multiple trigger', function (done) { - var index = 0; - - laydate.render({ - elem: '#test-div', - ready: function () { - index += 1; - } - }); - $('#test-div').click().click().click(); - - setTimeout(function () { - expect(index).to.equal(3); - done(); - }); - }); - }); - - it('options.elem', function () { - expect(function () { - laydate.render({ - elem: '#test-div' - }); - - laydate.render({ - elem: '#test-div-layui' - }); - - laydate.render({ - elem: '.ok-layui' - }); - }).to.not.throw; - - expect($('.layui-laydate').length).to.equal(0); }); describe('options.type', function () { @@ -170,149 +171,157 @@ describe('laydate', function () { }).config.type).to.equal('date', 'render 方法 options.type 默认值必须是 date'); }); - it('error value', function () { - expect(function () { - laydate.render({ - elem: '#test-div', - type: 'layui' - }); - }).to.throw(); - }); + // 先不作错误值的校验了 + // it('error value', function () { + // expect(function () { + // laydate.render({ + // elem: '#test-div', + // type: 'layui' + // }); + // }).to.throw(); + // }); - it('is year', function () { + it('is year', function (done) { var result = laydate.render({ elem: '#test-div', - type: 'year' + type: 'year', + show: true }); expect(result.config.type).to.equal('year'); - expect($('.laydate-set-ym').length).to.equal(0); - $('#test-div').click(); + setTimeout(function () { + expect($('.laydate-set-ym').length).to.equal(1, '标头年月元素必须存在'); + expect($('.laydate-year-list .layui-this').text()).to.equal(dateFormat('yyyy年'), '默认高亮显示当前年'); - expect($('.laydate-set-ym').length).to.equal(1); - expect($('.laydate-year-list .layui-this').text()).to.equal(dateFormat('yyyy年'), '默认高亮显示当前年'); - - $('.laydate-btns-confirm').click(); - expect($('#test-div').text()).to.equal(dateFormat('yyyy'), '确认后输出选中的值'); + $('.laydate-btns-confirm').click(); + expect($('#test-div').text()).to.equal(dateFormat('yyyy'), '确认后输出选中的值'); + done(); + }, 100); }); - it('is month', function () { + it('is month', function (done) { var result = laydate.render({ elem: '#test-div', - type: 'month' + type: 'month', + show: true }); expect(result.config.type).to.equal('month'); - expect($('.laydate-set-ym').length).to.equal(0); - $('#test-div').click(); + setTimeout(function () { + expect($('.laydate-set-ym').length).to.equal(1); + expect($('.laydate-month-list .layui-this').attr('lay-ym')) + .to.equal(dateFormat('M') - 1 + '', '默认高亮显示当前月'); - expect($('.laydate-set-ym').length).to.equal(1); - expect($('.laydate-month-list .layui-this').attr('lay-ym')) - .to.equal(dateFormat('M') - 1 + '', '默认高亮显示当前月'); - - $('.laydate-btns-confirm').click(); - expect($('#test-div').text()).to.equal(dateFormat('yyyy-MM'), '确认后输出选中的值'); + $('.laydate-btns-confirm').click(); + expect($('#test-div').text()).to.equal(dateFormat('yyyy-MM'), '确认后输出选中的值'); + done(); + }); }); - it('is date', function () { + it('is date', function (done) { var result = laydate.render({ elem: '#test-div', - type: 'date' + type: 'date', + show: true }); - var now = new Date(); expect(result.config.type).to.equal('date'); - expect($('.laydate-set-ym').length).to.equal(0); - $('#test-div').click(); + setTimeout(function () { + expect($('.laydate-set-ym').text()).to.equal(dateFormat('yyyy年M月'), '标头内显示当前年+月'); + expect($('.layui-laydate-content .layui-this').attr('lay-ymd')) + .to.equal(dateFormat('yyyy-M-d'), '默认高亮显示当前日'); - expect($('.laydate-set-ym').text()).to.equal(dateFormat('yyyy年M月'), '标头内显示当前年+月'); - expect($('.layui-laydate-content .layui-this').attr('lay-ymd')) - .to.equal(dateFormat('yyyy-M-d'), '默认高亮显示当前日'); - - $('.laydate-btns-confirm').click(); - expect($('#test-div').text()).to.equal(dateFormat('yyyy-MM-dd'), '确认后输出选中的值'); + $('.laydate-btns-confirm').click(); + expect($('#test-div').text()).to.equal(dateFormat('yyyy-MM-dd'), '确认后输出选中的值'); + done(); + }); }); - it('is time', function () { + it('is time', function (done) { var result = laydate.render({ elem: '#test-div', - type: 'time' + type: 'time', + show: true }); expect(result.config.type).to.equal('time'); - expect($('.laydate-time-text').length).to.equal(0); - $('#test-div').click(); + setTimeout(function () { + expect($('.laydate-time-text').text()).to.equal('选择时间', '标头内显示当前年+月'); + expect($('.laydate-time-list').length).to.equal(1); - expect($('.laydate-time-text').text()).to.equal('选择时间', '标头内显示当前年+月'); - expect($('.laydate-time-list').length).to.equal(1); - - expect($('#test-div').text()).to.equal(''); - $('.laydate-btns-confirm').click(); - expect($('#test-div').text()).to.equal('00:00:00'); + expect($('#test-div').text()).to.equal(''); + $('.laydate-btns-confirm').click(); + expect($('#test-div').text()).to.equal('00:00:00'); + done(); + }); }); - it('is datetime', function () { + it('is datetime', function (done) { var result = laydate.render({ elem: '#test-div', - type: 'datetime' + type: 'datetime', + show: true }); var now = new Date(); expect(result.config.type).to.equal('datetime'); - expect($('.laydate-set-ym').length).to.equal(0); - $('#test-div').click(); + setTimeout(function () { + expect($('.laydate-set-ym').text()).to.equal( + now.getFullYear() + '年' + (now.getMonth() + 1) + '月', + '标头内显示当前年+月' + ); + expect($('.layui-laydate-content .layui-this').attr('lay-ymd')).to.equal( + now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate(), + '默认高亮显示当前日' + ); + expect($('.laydate-btns-time').text()).to.equal('选择时间'); + expect($('.laydate-time-text').text()).to.equal(''); - expect($('.laydate-set-ym').text()).to.equal( - now.getFullYear() + '年' + (now.getMonth() + 1) + '月', - '标头内显示当前年+月' - ); - expect($('.layui-laydate-content .layui-this').attr('lay-ymd')).to.equal( - now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate(), - '默认高亮显示当前日' - ); - expect($('.laydate-btns-time').text()).to.equal('选择时间'); - expect($('.laydate-time-text').text()).to.equal(''); + // 断定选择时间的切换 + $('.laydate-btns-time').click(); + expect($('.laydate-time-text').text()).to.equal('选择时间'); + expect($('.laydate-btns-time').text()).to.equal('返回日期'); + $('.laydate-btns-time').click(); + expect($('.laydate-time-text').text()).to.equal(''); + expect($('.laydate-btns-time').text()).to.equal('选择时间'); - // 断定选择时间的切换 - $('.laydate-btns-time').click(); - expect($('.laydate-time-text').text()).to.equal('选择时间'); - expect($('.laydate-btns-time').text()).to.equal('返回日期'); - $('.laydate-btns-time').click(); - expect($('.laydate-time-text').text()).to.equal(''); - expect($('.laydate-btns-time').text()).to.equal('选择时间'); - - $('.laydate-btns-confirm').click(); - expect($('#test-div').text()).to.equal(dateFormat('yyyy-MM-dd 00:00:00'), '确认后输出选中的值'); + $('.laydate-btns-confirm').click(); + expect($('#test-div').text()).to.equal(dateFormat('yyyy-MM-dd 00:00:00'), '确认后输出选中的值'); + done(); + }); }); }); describe('options.range', function () { - it('time type and range', function () { + it('time type and range', function (done) { laydate.render({ elem: '#test-div', type: 'time', - range: true + range: true, + show: true }); - $('#test-div').click(); - expect($('.laydate-time-text').length).to.equal(2); - $('.laydate-btns-confirm').click(); - expect($('#test-div').text()).to.equal('00:00:00 - 00:00:00', '确认后输出范围值'); + setTimeout(function () { + expect($('.laydate-time-text').length).to.equal(2); + $('.laydate-btns-confirm').click(); + expect($('#test-div').text()).to.equal('00:00:00 - 00:00:00', '确认后输出范围值'); + done(); + }); }); it('year type and range is split', function () { laydate.render({ elem: '#test-div', type: 'year', - range: '到' + range: '到', + show: true }); - $('#test-div').click(); $('.laydate-btns-confirm').click(); expect($('#test-div').text()).to.match(/\d+\s到\s\d+/, '确认后输出范围值'); }); @@ -351,9 +360,83 @@ describe('laydate', function () { $('.laydate-btns-confirm').click(); expect($('#test-div').text()).to.equal(dateFormat('yyyy年的M月某天晚上,大概5点'), '确认后输出选中的值'); }); + + it('format and error value', function () { + laydate.render({ + elem: '#test-div', + value: '2017年7月7日', + format: 'yyyy~MM~dd' + }); + + expect($('#test-div').text()).to.equal('2017年7月7日', '默认输出value的值到元素中'); + $('#test-div').click(); + expect($('#test-div').text()).to.equal(dateFormat('yyyy~MM~dd'), '根据options.format修正value为当天'); + + // 错误提示 + expect($('.layui-laydate-hint').text()).to.match(/日期格式不合法/); + expect($('.layui-laydate-hint').text()).to.match(/yyyy~MM~dd/); + }); + + // 验证当format为 yyyyMMdd 和 value=20170707 时是否通过 + it('format and number value', function (done) { + laydate.render({ + elem: '#test-div', + value: '20170707', + format: 'yyyyMMdd', + show: true + }); + + laydate.render({ + elem: '#test-input', + value: '201777', + format: 'yyyyMd', + show: true + }); + + expect($('#test-div').text()).to.equal('20170707', '默认输出value的值到元素中'); + expect($('#test-input').val()).to.equal('201777', '默认输出value的值到元素中'); + + setTimeout(function () { + // 错误提示 + expect($('.layui-laydate-hint').length).to.equal(0, '格式正确没有错误提示'); + + done(); + }); + }); }); describe('options.value', function () { + it('2017-06-31', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-06-31', + done: function (value) { + expect(value).to.equal('2017-06-30', '6月最大为30号'); + done(); + } + }); + + $('.laydate-btns-confirm').click(); + }); + + it('new Date()', function (done) { + var date = new Date(); + date.setDate(date.getDate() + 1); + + laydate.render({ + elem: '#test-div', + show: true, + value: date, + done: function (value) { + expect(value).to.equal(dateFormat('yyyy-MM-dd', 1)); + done(); + } + }); + + $('.laydate-btns-confirm').click(); + }); + it('yyyy-MM-dd', function () { laydate.render({ elem: '#test-div', @@ -411,18 +494,1220 @@ describe('laydate', function () { createNode(''); laydate.render({ - elem: '#test-input-2' + elem: '#test-input-2', + show: true }); - $('#test-input-2').focus(); - // 错误提示 setTimeout(function () { expect($('.layui-laydate-hint').text()).to.match(/日期格式不合法/); done(); }); }); + + // 当元素值更新后, 再次显示日历时会更新 + it('change value', function () { + laydate.render({ + show: true, + value: '2017-3-7', + elem: '#test-div' + }); + + expect($('.layui-this').text()).to.equal('7', '显示默认的7'); + + $('.laydate-btns-confirm').click(); + $('#test-div').text('2017-7-10').click(); + expect($('.layui-this').text()).to.equal('10', '显示更新后的10'); + }); }); + + describe('options.min and options.max', function () { + it('date string', function () { + laydate.render({ + elem: '#test-div', + min: '2017-7-7', + max: '2017-7-8' + }); + + $('#test-div').click(); + $('.laydate-set-ym').find('[lay-type="year"]').click(); + expect($('.laydate-year-list .layui-this').text()).to.equal('2017年'); + + // 只有2017年可用 + expect($('.laydate-year-list [lay-ym="2016"]').hasClass('laydate-disabled')).to.be.true; + expect($('.laydate-year-list [lay-ym="2018"]').hasClass('laydate-disabled')).to.be.true; + + $('#test-div').click(); + $('.laydate-set-ym').find('[lay-type="month"]').click(); + + // 只有7月可用 + expect($('.laydate-month-list [lay-ym="5"]').hasClass('laydate-disabled')).to.be.true; + expect($('.laydate-month-list [lay-ym="7"]').hasClass('laydate-disabled')).to.be.true; + }); + + // 错误字符串时直接设为当天最小 + it('error string', function () { + laydate.render({ + elem: '#test-div', + min: 'layui', + max: 'layui' + }); + + $('#test-div').click(); + + expect($('.layui-laydate-content .layui-this').attr('lay-ymd')).to.equal(dateFormat('yyyy-M-d'), '默认选中日期'); + + // 昨天不可用, 判断是为了处理跨月 + var $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', -1) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.true; + } + + // 明天不可用, 判断是为了处理跨月 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', 1) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.true; + } + }); + + it('date number', function () { + laydate.render({ + elem: '#test-div', + min: -2, + max: 2 + }); + + $('#test-div').click(); + + // 前两天应该是可用, 判断是为了处理跨月 + var $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', -2) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.false; + } + + // 前三天应该是禁用的 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', -3) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.true; + } + + // 后两天可用 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', 2) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.false; + } + + // 后三天禁用 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', 3) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.true; + } + }); + + it('timestamp', function () { + var date = new Date(); + var date2 = new Date(); + + // 获取前三天的时间缀 + date.setDate(date.getDate() + -3); + date2.setDate(date2.getDate() + 3); + + laydate.render({ + elem: '#test-div', + min: date.getTime(), + max: date2.getTime() + }); + + $('#test-div').click(); + + // 前三天可用, 防止跨月 + var $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', -3) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.false; + } + + // 前四天不可用 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', -4) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.true; + } + + // 后三天可用 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', 3) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.false; + } + + // 后四天不可用 + $elem = $('.layui-laydate-content [lay-ymd="' + dateFormat('yyyy-M-d', 4) + '"]'); + if ($elem.length) { + expect($elem.hasClass('laydate-disabled')).to.be.true; + } + }); + + it('and options.value', function () { + laydate.render({ + elem: '#test-div', + min: '2017-7-7', + max: '2017-7-7', + value: '2017-7-7' + }); + + $('#test-div').click(); + + expect($('.layui-laydate-content .layui-this').attr('lay-ymd')).to.equal('2017-7-7', '默认选中日期'); + expect($('.layui-laydate-content [lay-ymd="2017-7-6"]').hasClass('laydate-disabled')).to.be.true; + expect($('.layui-laydate-content [lay-ymd="2017-7-8"]').hasClass('laydate-disabled')).to.be.true; + }); + + // 当最大小于最小时, 日期选择都不可用 + it('options.max < options.min', function () { + laydate.render({ + elem: '#test-div', + min: '2017-7-7', + max: '2017-7-1' + }); + + $('#test-div').click(); + $('.laydate-set-ym').find('[lay-type="year"]').click(); + + // 查找可用的年 + var year = $('.laydate-year-list li').filter(function () { + return !$(this).hasClass('laydate-disabled'); + }).get(); + expect(year.length).to.equal(0); + + $('#test-div').click(); + $('.laydate-set-ym').find('[lay-type="month"]').click(); + + // 查找可用的月 + var month = $('.laydate-month-list li').filter(function () { + return !$(this).hasClass('laydate-disabled'); + }).get(); + expect(month.length).to.equal(0); + }); + }); + + describe('options.trigger', function () { + it('default value', function () { + var result = laydate.render({ + elem: '#test-input' + }); + expect(result.config.trigger).to.equal('focus'); + + result = laydate.render({ + elem: '#test-div' + }); + // div会默认转成click + expect(result.config.trigger).to.equal('click'); + }); + + it('not click', function (done) { + laydate.render({ + elem: '#test-div', + trigger: 'layui', + ready: done + }); + + $('#test-div').click(); + + setTimeout(done); + }); + }); + + describe('options.show', function () { + it('default value', function (done) { + laydate.render({ + elem: '#test-div', + ready: done + }); + setTimeout(done); + }); + + it('show is true', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + ready: function () { + done(); + } + }); + }); + + // 以下2个是测试和`options.closeStop`的配合 + it('element trigger show', function (done) { + createNode(''); + $('#test-trigger-show').on('click', function () { + laydate.render({ + elem: '#test-div', + show: true + }); + }).click(); + + setTimeout(function () { + expect($('.layui-laydate').length).to.equal(0); + done(); + }, 100); + }); + it('element trigger show and options.closeStop', function (done) { + createNode(''); + $('#test-trigger-show').on('click', function () { + laydate.render({ + elem: '#test-div', + show: true, + closeStop: '#test-trigger-show' + }); + }).click(); + + setTimeout(function () { + expect($('.layui-laydate').length).to.equal(1); + done(); + }, 100); + }); + }); + + describe('options.position', function () { + it('static', function () { + laydate.render({ + elem: '#test-div', + position: 'static' + }); + + expect($('#test-div').find('.layui-laydate-static').length).to.equal(1); + }); + + it('fixed', function () { + laydate.render({ + elem: '#test-div', + position: 'fixed', + show: true + }); + + expect($('.layui-laydate').css('position')).to.equal('fixed'); + }); + }); + + describe('options.zIndex', function () { + it('options.position is fixed', function () { + laydate.render({ + elem: '#test-div', + position: 'fixed', + show: true, + zIndex: 10086 + }); + + expect($('.layui-laydate').css('zIndex')).to.equal('10086'); + }); + + it('options.position is abolute', function () { + laydate.render({ + elem: '#test-div', + show: true, + position: 'abolute', + zIndex: 10086 + }); + + expect($('.layui-laydate').css('zIndex')).to.equal('10086'); + }); + + it('options.position is static', function () { + laydate.render({ + elem: '#test-div', + position: 'static', + show: true, + zIndex: 10086 + }); + + expect($('.layui-laydate').css('zIndex')).to.equal('10086'); + }); + }); + + describe('options.showBottom', function () { + it('default value', function () { + laydate.render({ + elem: '#test-div', + show: true + }); + + expect($('.layui-laydate-footer').length).to.equal(1); + }); + + it('is false', function () { + laydate.render({ + elem: '#test-div', + show: true, + showBottom: false + }); + + expect($('.layui-laydate-footer').length).to.equal(0); + }); + }); + + describe('options.btns', function () { + it('default value', function () { + laydate.render({ + elem: '#test-div', + show: true + }); + + var btns = $('.laydate-footer-btns span').map(function () { + return $(this).attr('lay-type'); + }).get(); + + expect(btns).to.deep.equal([ + 'clear', + 'now', + 'confirm' + ]); + }); + + it('[confirm, now]', function () { + laydate.render({ + elem: '#test-div', + show: true, + btns: ['confirm', 'now'] + }); + + var btns = $('.laydate-footer-btns span').map(function () { + return $(this).attr('lay-type'); + }).get(); + + expect(btns).to.deep.equal([ + 'confirm', + 'now' + ]); + }); + + it('error value', function () { + laydate.render({ + elem: '#test-div', + show: true, + btns: ['layui'] + }); + + var btns = $('.laydate-footer-btns span').map(function () { + return $(this).attr('lay-type'); + }).get(); + + expect(btns).to.deep.equal([ + 'layui' + ]); + }); + }); + + describe('options.lang', function () { + it('default value is cn', function () { + var result = laydate.render({ + show: true, + elem: '#test-div' + }); + + var weeks = $('.layui-laydate-content').find('thead th').map(function () { + return $(this).text(); + }).get(); + expect(weeks).to.deep.equal(['日', '一', '二', '三', '四', '五', '六'], 'cn版本星期的标头'); + + expect($('.laydate-btns-confirm').text()).to.equal('确定', 'cn版本确定按钮'); + expect($('.laydate-btns-now').text()).to.equal('现在', 'cn版本当前按钮'); + expect($('.laydate-btns-clear').text()).to.equal('清空', 'cn版本清除按钮'); + expect(result.config.lang).to.equal('cn'); + }); + + it('en', function () { + var result = laydate.render({ + show: true, + lang: 'en', + elem: '#test-div' + }); + + var weeks = $('.layui-laydate-content').find('thead th').map(function () { + return $(this).text(); + }).get(); + expect(weeks).to.deep.equal(['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'], 'en版本星期的标头'); + + expect($('.laydate-btns-confirm').text()).to.equal('Confirm', 'en版本确定按钮'); + expect($('.laydate-btns-now').text()).to.equal('Now', 'en版本当前按钮'); + expect($('.laydate-btns-clear').text()).to.equal('Clear', 'en版本清除按钮'); + expect(result.config.lang).to.equal('en'); + }); + + it('error vaue', function () { + var result = laydate.render({ + show: true, + lang: 'layui', + elem: '#test-div' + }); + + expect($('.laydate-btns-confirm').text()).to.equal('确定', 'lang错误时默认为中文'); + expect(result.config.lang).to.equal('layui'); + }); + + // todo month, time, timeTips + }); + + describe('options.theme', function () { + it('molv', function () { + laydate.render({ + show: true, + elem: '#test-div', + theme: 'molv' + }); + + expect($('.laydate-theme-molv').length).to.equal(1, '墨绿主题class存在'); + }); + + it('grid', function () { + laydate.render({ + show: true, + elem: '#test-div', + theme: 'grid' + }); + + expect($('.laydate-theme-grid').length).to.equal(1, '格子主题class存在'); + }); + + it('error value', function () { + laydate.render({ + show: true, + elem: '#test-div', + theme: 'layui-test' + }); + + expect($('.laydate-theme-layui-test').length).to.equal(1, '自定义主题class存在'); + }); + + it('#color', function () { + // 主要处理多浏览器兼容 + var colors = [ + 'rgb(0, 0, 0)', + 'rgba(0, 0, 0, 0)', + '#000' + ]; + + laydate.render({ + show: true, + elem: '#test-div', + theme: '#000' + }); + + $.each([ + '.layui-this', + '.layui-laydate-header' + ], function (index, selector) { + expect(colors).to.includes($(selector).css('background-color'), '标头和当前选中颜色必须是设置的'); + }); + }); + }); + + describe('options.calendar', function () { + it('default value', function () { + var result = laydate.render({ + elem: '#test-div', + show: true, + value: '2017-3-8' + }); + + expect(result.config.calendar).to.equal(false, '默认值为false'); + expect($('.layui-this').text()).to.equal('8', '显示数字'); + }); + + it('is true', function () { + var result = laydate.render({ + elem: '#test-div', + show: true, + value: '2017-3-8', + calendar: true + }); + + expect(result.config.calendar).to.equal(true, '默认值为false'); + expect($('.layui-this').text()).to.equal('妇女', '显示妇女节'); + }); + + it('options.lang is en', function () { + laydate.render({ + elem: '#test-div', + show: true, + lang: 'en', + value: '2017-3-8' + }); + + expect($('.layui-this').text()).to.equal('8', '国际版显示数字'); + }); + }); + + describe('options.mark', function () { + it('every year', function () { + laydate.render({ + mark: { + '0-3-7': '妹子' + }, + show: true, + value: '2017-3-7', + elem: '#test-div' + }); + + expect($('.layui-this').text()).to.equal('妹子', '显示自定义的妹子'); + + // 再看下4月7日 + $('.laydate-btns-confirm').click(); + $('#test-div').text('2017-4-7').click(); + expect($('.layui-this').text()).to.equal('7', '显示日期'); + }); + + it('every year and month', function () { + laydate.render({ + mark: { + '0-0-7': '妹子' + }, + show: true, + value: '2017-7-7', + elem: '#test-div' + }); + + expect($('.layui-this').text()).to.equal('妹子', '显示自定义的妹子'); + + // 再看下4月7日 + $('.laydate-btns-confirm').click(); + $('#test-div').text('2017-4-7').click(); + expect($('.layui-this').text()).to.equal('妹子', '显示自定义的妹子'); + }); + + it('yyyy-M-d', function () { + laydate.render({ + mark: { + '2017-3-7': '妹子' + }, + show: true, + value: '2017-3-7', + elem: '#test-div' + }); + + expect($('.layui-this').text()).to.equal('妹子', '显示自定义的妹子'); + + // 再看下2016年 + $('.laydate-btns-confirm').click(); + $('#test-div').text('2016-3-7').click(); + expect($('.layui-this').text()).to.equal('7', '显示日期'); + }); + + it('options.calendar is true', function () { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-3-8', + mark: { + '2017-3-8': '快乐' + }, + calendar: true + }); + + expect($('.layui-this').text()).to.equal('快乐', '显示被mark覆盖的 快乐'); + }); + }); + + // 基于phantomjs测试内部方法 + if (IS_PHANTOMJS) { + it('options.dateTime', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + dateTime: { + year: 20000000, + month: 15, + minutes: 70, + seconds: 60, + hours: 25 + }, + done: function (value) { + expect(value).to.equal(dateFormat('yyyy-MM-dd'), '设置日期超出范围, 初始化为当天'); + done(); + } + }); + + $('.laydate-btns-confirm').click(); + }); + } + }); + + describe('callbacks', function () { + describe('render', function () { + it('not elem', function (done) { + var flag = true; + laydate.render({ + ready: function () { + flag = false; + } + }); + + setTimeout(function () { + expect(flag).to.be.true; + done(); + }, 360); + }); + + it('trigger', function (done) { + laydate.render({ + elem: '#test-div', + ready: function (data) { + expect(data).to.be.a('object'); + done(); + } + }); + + $('#test-div').click(); + }); + + // 如果是div则自动切换成click + it('multiple trigger', function (done) { + var index = 0; + + laydate.render({ + elem: '#test-div', + ready: function () { + index += 1; + } + }); + $('#test-div').click().click().click(); + + setTimeout(function () { + expect(index).to.equal(3); + done(); + }); + }); + + // 当show=true时应该直接显示并执行ready事件 + it('options.show is true', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + ready: function (data) { + expect(data).to.be.a('object'); + done(); + } + }); + }); + }); + + describe('change', function () { + it('trigger', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-07-07', + range: false, + change: function (value, date, endDate) { + expect(value).to.equal('2017-08-07', '进入下一月的日期'); + expect(date).to.deep.equal({ + year: 2017, + month: 8, + date: 7, + hours: 0, + minutes: 0, + seconds: 0 + }, '进入下一月的日期时间对象'); + expect(endDate).to.deep.equal({}, '没有开启 options.range 时 endDate 为空对象'); + + done(); + } + }); + + $('.laydate-next-m').click(); + }); + + it('options.range is true', function (done) { + laydate.render({ + elem: '#test-div', + range: true, + show: true, + change: function (value, date, endDate) { + var start = dateFormat('yyyy-MM-dd'); + var end = dateFormat('yyyy-MM-dd', 1); + + expect(value).to.equal(start + ' - ' + end, '进入下一月的日期'); + expect(date).to.be.a('Object'); + expect(date).to.not.deep.equal({}); + expect(endDate).to.be.a('Object'); + expect(endDate).to.not.deep.equal({}, '开启 options.range 时 endDate 不能为空'); + + done(); + } + }); + + // 模拟点击当天和下一天 + $('[lay-ymd="' + dateFormat('yyyy-M-d') + '"]').click(); + $('[lay-ymd="' + dateFormat('yyyy-M-d', 1) + '"]').click(); + }); + }); + + describe('done', function () { + it('click date', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-07-07', + range: false, + done: function (value, date, endDate) { + expect(value).to.equal('2017-07-07'); + expect(date).to.deep.equal({ + year: 2017, + month: 7, + date: 7, + hours: 0, + minutes: 0, + seconds: 0 + }); + expect(endDate).to.deep.equal({}); + + done(); + } + }); + + $('.layui-this').click(); + }); + + it('click confirm btn', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-07-07', + range: false, + done: function (value, date, endDate) { + expect(value).to.equal('2017-07-07'); + expect(date).to.deep.equal({ + year: 2017, + month: 7, + date: 7, + hours: 0, + minutes: 0, + seconds: 0 + }); + expect(endDate).to.deep.equal({}); + + done(); + } + }); + + $('.laydate-btns-confirm').click(); + }); + + it('click clear btn', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-07-07', + range: false, + done: function (value, date, endDate) { + expect(value).to.equal(''); + expect(date).to.deep.equal({}); + expect(endDate).to.deep.equal({}); + + done(); + } + }); + + $('.laydate-btns-clear').click(); + }); + + it('click now btn', function (done) { + laydate.render({ + elem: '#test-div', + show: true, + value: '2017-07-07', + range: false, + done: function (value, date, endDate) { + expect(value).to.equal(dateFormat('yyyy-MM-dd')); + + done(); + } + }); + + $('.laydate-btns-now').click(); + }); + }); + }); + + describe('#hint', function () { + it('set string', function () { + var app = laydate.render({ + elem: '#test-div', + show: true + }); + + expect(app.hint).to.be.a('function', '.hint 必须是方法'); + app.hint('layui'); + expect($('.layui-laydate-hint').text()).to.equal('layui'); + }); + + it('timeout 3000', function (done) { + var app = laydate.render({ + elem: '#test-div', + show: true + }); + + app.hint('layui'); + expect($('.layui-laydate-hint').length).to.equal(1); + setTimeout(function () { + expect($('.layui-laydate-hint').length).to.equal(0); + done(); + }, 3500); + }); + }); + describe('.getEndDate', function () { + it('default params and return value', function () { + expect(laydate.getEndDate).to.be.a('function', 'laydate.getEndDate 必须是方法'); + expect(laydate.getEndDate()).to.be.a('number', 'laydate.getEndDate 返回值必须是数字'); + expect(laydate.getEndDate(10, 2017)).to.be.a('number', 'laydate.getEndDate 返回值必须是数字'); + expect(laydate.getEndDate(10)).to.be.a('number', 'laydate.getEndDate 返回值必须是数字'); + }); + + it('getEndDate(year)', function () { + expect(laydate.getEndDate(10)).to.equal(31, '10月最后一天为31'); + expect(laydate.getEndDate(11)).to.equal(30, '11月最后一天为30'); + expect(laydate.getEndDate(11, 2017)).to.equal(30, '2017年11月最后一天为30'); + expect(laydate.getEndDate(10, 2017)).to.equal(31, '2017年10月最后一天为31'); + expect(laydate.getEndDate(2, 2017)).to.equal(28, '2017年2月最后一天为28'); + expect(laydate.getEndDate(2, 2016)).to.equal(29, '2016年2月最后一天为29'); + }); + }); + + describe('lay', function () { + describe('lay.stope', function () { + it('stopPropagation', function (done) { + lay.stope({ + stopPropagation: function (e) { + expect(e).to.be.undefined; + done(); + } + }); + }); + + it('cancelBubble', function () { + var event = {}; + lay.stope(event); + expect(event.cancelBubble).to.be.true; + }); + + // ie中不支持, 只针对phantomjs测试 + if (IS_PHANTOMJS) { + it('window.event', function () { + var old = window.event; + var event = window.event = {}; + lay.stope(); + expect(event.cancelBubble).to.be.true; + window.event = old; + }); + } + }); + + describe('lay.extend', function () { + it('default params and return value', function () { + expect(lay.extend).to.be.a('function', '必须是方法'); + expect(lay.extend()).to.be.a('object', '返回值必须是对象'); + expect(lay.extend({})).to.be.a('object', '返回值必须是对象'); + expect(lay.extend({}, {})).to.be.a('object', '返回值必须是对象'); + }); + + it('multiple object', function () { + expect(lay.extend({}, {})).to.deep.equal({}); + expect(lay.extend(true, {})).to.deep.equal({}); + expect(lay.extend(true, {a: 1}, {b: 2})).to.deep.equal({ + a: 1, + b: 2 + }, '合并多个对象'); + expect(lay.extend({a: 1}, {b: 2})).to.deep.equal({ + a: 1, + b: 2 + }, '合并多个对象'); + }); + + it('recursion merge', function () { + expect(lay.extend({ + a: 1, + b: { + b1: 1 + } + }, { + b: { + b2: 1, + b3: [1] + } + }, { + c: null + })).to.deep.equal({ + a: 1, + b: { + b1: 1, + b2: 1, + b3: [1] + }, + c: null + }); + }); + + it('clone object', function () { + var a = {}; + lay.extend(a, { + b: 1 + }, { + c: [] + }); + + expect(a.b).to.equal(1, '污染了原对象'); + expect(a.c).to.deep.equal([], '污染了原对象'); + }); + }); + + describe('lay.each', function () { + it('check params', function () { + expect(lay.each).to.be.a('function', '必须是方法'); + expect(lay.each()).to.deep.equal(lay, '返回值判断'); + expect(lay.each({})).to.deep.equal(lay); + expect(lay.each([])).to.deep.equal(lay); + expect(lay.each({}, function () {})).to.deep.equal(lay); + }); + + it('null params', function (done) { + var index = 0; + lay.each(null, function (index) { + index += 1; + }); + setTimeout(function () { + expect(index).to.equal(0); + done(); + }); + }); + + it('object each', function (done) { + lay.each({ + name: 'layui' + }, function (key, value) { + expect(this + '').to.deep.equal(value).and.equal('layui'); + expect(key).to.equal('name'); + done(); + }); + }); + + it('array each', function (done) { + lay.each([ + 'layui' + ], function (index, value) { + expect(this + '').to.deep.equal(value).and.equal('layui'); + expect(index).to.equal(0); + done(); + }); + }); + + it('break array each', function () { + var arr = new Array(100).join(',').split(','); + var flag = -1; + lay.each(arr, function (index) { + flag = index; + if (index > 5) { + return true; + } + }); + expect(flag).to.equal(6); + + flag = -1; + lay.each(arr, function (index) { + flag = index; + if (index > 5) { + return false; + } + }); + expect(flag).to.equal(99); + }); + + it('break object each', function () { + var obj = { + name: 'layui', + version: '2.x' + }; + var flag = null; + lay.each(obj, function (key) { + flag = key; + return true; + }); + expect(flag).to.equal('name'); + + flag = null; + lay.each(obj, function (key) { + flag = key; + return false; + }); + expect(flag).to.equal('version'); + }); + }); + + describe('lay.elem', function () { + it('create div', function () { + expect(lay.elem('div')).to.be.an.instanceof(HTMLElement, '必须是 html 节点'); + }); + + it('has error', function () { + expect(function () { + lay.elem([]); + }).to.throw; + + expect(function () { + lay.elem(); + }).to.throw; + }); + + it('set attrs', function () { + var node = lay.elem('div', { + 'data-name': 'layui' + }); + + expect($(node).attr('data-name')).to.equal('layui'); + }); + }); + + describe('lay.digit', function () { + it('default params and return value', function () { + expect(lay.digit).to.be.a('function', '必须是方法'); + expect(lay.digit()).to.equal('undefined', '无参数时返回 undefined'); + }); + + it('default length', function () { + expect(lay.digit(1)).to.equal('01'); + expect(lay.digit(1)).to.equal(lay.digit(1, 2)); + expect(lay.digit(11)).to.equal('11'); + expect(lay.digit('111')).to.equal('111'); + }); + + it('set length', function () { + expect(lay.digit(1, 1)).to.equal('1'); + expect(lay.digit(1, 2)).to.equal('01'); + expect(lay.digit(11, 1)).to.equal('11'); + expect(lay.digit('11', 10)).to.equal('0000000011', '补10位'); + expect(lay.digit(1, 5)).to.equal('00001'); + expect(lay.digit(1, 100).length).to.equal(100, '补100位'); + }); + }); + + if (IS_PHANTOMJS) { + it('lay.ie', function () { + expect(lay.ie).to.be.a('boolean'); + }); + } + }); + + describe('lay()', function () { + it('return value', function () { + expect(lay).to.be.a('function', '必须是方法'); + expect(lay()).to.be.a('object'); + }); + + it('#find', function () { + expect(lay('body').find()[0]).to.be.undefined; + expect(lay('body').find('.test-test-empty')[0]).to.be.undefined; + expect(lay('body').find('div')[0]).to.not.be.undefined; + }); + + it('#addClass', function () { + var $node = lay('#test-div'); + + expect($('#test-div').hasClass('layui')).to.be.false; + expect($node.addClass('layui')).to.deep.equal($node); + expect($('#test-div').hasClass('layui')).to.be.true; + }); + + it('#removeClass', function () { + var $node = lay('#test-div'); + + lay('#test-div').addClass('layui'); + expect($('#test-div').hasClass('layui')).to.be.true; + expect($node.removeClass('layui')).to.deep.equal($node); + expect($('#test-div').hasClass('layui')).to.be.false; + }); + + it('#hasClass', function () { + expect(lay('#test-div').hasClass('layui')).to.be.false; + lay('#test-div').addClass('layui'); + expect(lay('#test-div').hasClass('layui')).to.be.true; + lay('#test-div').removeClass('layui'); + expect(lay('#test-div').hasClass('layui')).to.be.false; + }); + + it('#attr', function () { + $('#test-div').attr('data-name', 'layui'); + expect(lay('#test-div').attr('data-name')).to.equal('layui'); + + var $node = lay('#test-div'); + expect($node.attr('data-name', 'layui-2')).to.deep.equal($node); + expect(lay('#test-div').attr('data-name')).to.equal('layui-2'); + + expect(lay('#test-test-empty').attr('data-name')).to.be.undefined; + }); + + it('#removeAttr', function () { + var $node = lay('#test-div'); + + lay('#test-div').attr('data-name', 'layui'); + expect(lay('#test-div').attr('data-name')).to.equal('layui'); + + expect(lay('#test-div').removeAttr('data-name')).to.deep.equal($node); + expect(lay('#test-div').attr('data-name')).to.not.equal('layui'); + }); + + it('#html', function () { + var str = 'layui'; + var $node = lay('#test-div'); + expect($node.html(str)).to.deep.equal($node); + + expect($('#test-div').html()).to.equal(str); + }); + + it('#val', function () { + var $node = lay('#test-input'); + expect($node.val('layui')).to.deep.equal($node); + expect($('#test-input').val()).to.equal('layui'); + }); + + it('#append', function () { + var $node = lay('#test-div'); + + expect($node.append('1')).to.deep.equal($node); + lay('#test-div').append('2'); + expect($('#test-div').html()).to.equal('12'); + $('#test-div').empty(); + + var node = $('').html('layui').get(0); + lay('#test-div').append(node); + expect($('#test-div').html()).to.equal('layui'); + }); + + it('#remove', function () { + lay('#test-div').append('
1
'); + expect($('#test-div').children().length).to.equal(1); + lay('#test-div').remove($('#test-div').children().get(0)); + expect($('#test-div').children().length).to.equal(0); + + lay('#test-div').append('
1
'); + expect($('#test-div').children().length).to.equal(1); + lay('#test-div div').remove(); + expect($('#test-div').children().length).to.equal(0); + }); + + it('#on', function (done) { + lay('#test-div').on('click', function (event) { + expect(event).to.be.not.undefined; + done(); + }); + $('#test-div').click(); + }); + + // it('#off', function (done) { + // var fn = function () { + // done('off error'); + // }; + // lay('#test-div').on('click', fn).off('click', fn); + // $('#test-div').click(); + // setTimeout(function () { + // done(); + // }); + // }); }); }); diff --git a/test/layui.js b/test/layui.js index 5f7b9c2..9b69142 100644 --- a/test/layui.js +++ b/test/layui.js @@ -194,7 +194,7 @@ describe('layui', function () { }); it('error callback', function (done) { - layui.img('/404/404.gif', function () {}, function (e) { + layui.img('/api/mock?statusCode=404', function () {}, function (e) { expect(e).to.not.undefined; done(); });