Skip to content

Commit a0e34d9

Browse files
committed
update test
1 parent 65e3c07 commit a0e34d9

File tree

12 files changed

+34
-27
lines changed

12 files changed

+34
-27
lines changed

demo/demo.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
initTest();
2929
} else {
3030
$i = $('#test').bsSuggest(method);
31-
console.log($i);
31+
if (typeof $i === 'object') {
32+
$i = $i.data('bsSuggest');
33+
}
34+
console.log(method, $i);
3235
if (!$i) {
3336
alert('未初始化或已销毁');
3437
}

src/bootstrap-suggest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@
838838
});
839839
//只要有一个未初始化,则全部都不执行方法,除非是 init 或 version
840840
if (!inited && 'init' !== options && 'version' !== options) {
841-
return false;
841+
return this;
842842
}
843843

844844
//如果是方法,则参数第一个为函数名,从第二个开始为函数参数

test/helper/helper-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
var lintAsync = window.lintAsync;
88

99
window.helperTest = {
10+
initInput: function($input, param) {
11+
return $input.bsSuggest('hide').bsSuggest('destroy').val('').bsSuggest(param);
12+
},
1013
/**
1114
* 基本方法测试
1215
*/

test/helper/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function mochaRun() {
2-
mocha.checkLeaks();
3-
mocha.globals(['jQuery']);
2+
// mocha.checkLeaks();
3+
// mocha.globals(['jQuery']);
44
mocha.run();
55
}
66

test/helper/setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function setup() {
5555

5656
window.mocha.setup({
5757
ui: 'bdd',
58+
ignoreLeaks: true,
5859
timeout: 10000
5960
});
6061

test/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
margin-top: 1.2rem;
1414
border-bottom: 1px #eee solid;
1515
}
16+
#mocha {
17+
min-height: 600px;
18+
}
1619
.container {
17-
margin-top: 600px;
1820
margin-bottom: 160px;
1921
}
2022
</style>

test/spec/test.1.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ describe('测试一:(首次从 URL 获取数据)', function() {
1515

1616
it('基本初始化,数据请求成功测试', function(done) {
1717
lintAsync(function($d) {
18-
$input.val('').bsSuggest('destroy');
19-
$input.bsSuggest(param).one('onDataRequestSuccess', function(e, result) {
20-
expect(result).to.have.property('value').with.length(31);
21-
$d.resolve();
22-
done();
23-
});
18+
window.helperTest.initInput($input, param)
19+
.one('onDataRequestSuccess', function(e, result) {
20+
expect(result).to.have.property('value').with.length(31);
21+
$d.resolve();
22+
done();
23+
});
2424
});
2525
});
2626

test/spec/test.2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('测试二:(首次从 URL 获取数据,显示 header,不显示按
2020

2121
it('基本初始化,数据延迟测试,不显示按钮测试', function() {
2222
return lintAsync(function() {
23-
$input.bsSuggest('destroy').val('').bsSuggest(param);
23+
window.helperTest.initInput($input, param);
2424
}).then(function() {
2525
expect($input.data('bsSuggest').options.data.value.length).to.equal(0);
2626
expect($input.next().find('button').is(':visible')).to.be.false;

test/spec/test.3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ describe('测试三:(从 json.data 中获取数据)', function() {
2424

2525
it('基本初始化测试', function() {
2626
return lintAsync(function() {
27-
$input.val('').bsSuggest('destroy');
28-
$input.bsSuggest(param).trigger('keydown').trigger('keyup');
27+
window.helperTest.initInput($input, param)
28+
.trigger('keydown').trigger('keyup');
2929
}).then(function() {
3030
expect($input.data('bsSuggest').options.data.value.length).to.equal(50);
3131
expect($input.next().find('button').is(':visible')).to.be.true;

test/spec/test.4.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@ describe('测试四:(自动判断向上/下测试: autoDropup: true)', functio
2020

2121
it('基本初始化,数据请求成功测试', function() {
2222
return lintAsync(function($d) {
23-
$input.val('').bsSuggest('destroy');
24-
$input.bsSuggest(param).one('onDataRequestSuccess', function(e, result) {
25-
26-
expect(result).to.have.property('value').with.length(31);
27-
$d.resolve();
28-
});
23+
window.helperTest.initInput($input, param)
24+
.one('onDataRequestSuccess', function(e, result) {
25+
expect(result).to.have.property('value').with.length(31);
26+
$d.resolve();
27+
});
2928
});
3029
});
3130

0 commit comments

Comments
 (0)