mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-04-24 00:00:03 +08:00
- improved test app
- defined new tests
This commit is contained in:
@@ -5,35 +5,53 @@ const app = {
|
||||
document.getElementById('nextBtn').addEventListener('click', app.onNextBtnClick);
|
||||
},
|
||||
|
||||
print: function(prefix, content) {
|
||||
const text = '\n' + prefix + ': ' + JSON.stringify(content);
|
||||
printResult: function(prefix, content) {
|
||||
const text = prefix + ': ' + JSON.stringify(content);
|
||||
|
||||
document.getElementById('resultTextarea').value += text;
|
||||
},
|
||||
|
||||
reject: function(content) {
|
||||
app.print('result - rejected', content);
|
||||
app.printResult('result - rejected', content);
|
||||
},
|
||||
|
||||
resolve: function(content) {
|
||||
app.print('result - resolved', content);
|
||||
app.printResult('result - resolved', content);
|
||||
},
|
||||
|
||||
runTest: function(index) {
|
||||
const testDefinition = tests[index];
|
||||
const titleText = app.testIndex + ': ' + testDefinition.description;
|
||||
const resultText = 'expectation - ' + testDefinition.expected;
|
||||
const expectedText = 'expected - ' + testDefinition.expected;
|
||||
|
||||
document.getElementById('resultTextarea').value = resultText;
|
||||
document.getElementById('expectedTextarea').value = expectedText;
|
||||
document.getElementById('resultTextarea').value = '';
|
||||
document.getElementById('descriptionLbl').innerText = titleText;
|
||||
testDefinition.func(index);
|
||||
testDefinition.func(app.resolve, app.reject);
|
||||
},
|
||||
|
||||
onBeforeTest: function(testIndex, cb) {
|
||||
if (hooks && hooks.onBeforeEachTest) {
|
||||
return hooks.onBeforeEachTest(function() {
|
||||
const testDefinition = tests[testIndex];
|
||||
|
||||
if (testDefinition.before) {
|
||||
testDefinition.before(cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
},
|
||||
|
||||
onFinishedAllTests: function() {
|
||||
const titleText = 'No more tests';
|
||||
const resultText = 'You have run all available tests.';
|
||||
const expectedText = 'You have run all available tests.';
|
||||
|
||||
document.getElementById('resultTextarea').value = resultText;
|
||||
document.getElementById('expectedTextarea').value = expectedText;
|
||||
document.getElementById('resultTextarea').value = '';
|
||||
document.getElementById('descriptionLbl').innerText = titleText;
|
||||
},
|
||||
|
||||
@@ -41,7 +59,9 @@ const app = {
|
||||
app.testIndex += 1;
|
||||
|
||||
if (app.testIndex < tests.length) {
|
||||
app.runTest(app.testIndex);
|
||||
app.onBeforeTest(app.testIndex, function() {
|
||||
app.runTest(app.testIndex);
|
||||
});
|
||||
} else {
|
||||
app.onFinishedAllTests();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user