-
-
Save Luchanso/c4f7bf2fe6d68f1b4aaf to your computer and use it in GitHub Desktop.
Найти ошибку в коде
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var database = { | |
myString: "hello world", | |
myNumber: 12 | |
} | |
function getFieldFromDB(callback, field) { | |
setTimeout(function() { | |
if (database == field) { | |
callback(null, database[field]); | |
} else { | |
callback('поле не найдено', database[field]); | |
} | |
}, 1000); | |
} | |
function prepareData(error, data) { | |
if (error) { | |
console.log('Ошибка: ' + error); | |
return; | |
} | |
console.log("Запрошенные данные: " + data); | |
} | |
function main() { | |
getFieldFromDB(prepareData, 'myString'); | |
getFieldFromDB(prepareData, 'myCat'); | |
getFieldFromDB(prepareData, 'myNumber'); | |
} | |
function test() { | |
getFieldFromDB(function(error, data) { | |
if (error) { | |
return console.log('Тест 1 не пройден - найдены ошибки'); | |
} else if (data != database.myString) { | |
return console.log('Тест 1 не пройден - пришли неправильные данные'); | |
} | |
console.log('==== Тест 1 пройден успешно ===='); | |
}, 'myString'); | |
getFieldFromDB(function(error, data) { | |
if (!error) { | |
return console.log('Тест 2 не пройден - обнаружена неправильная обработка ошибок'); | |
} | |
console.log('==== Тест 2 пройден успешно ===='); | |
}, 'myCat'); | |
getFieldFromDB(function(error, data) { | |
if (error) { | |
return console.log('Тест 3 не пройден - найдены ошибки'); | |
} else if (data != database.myNumber) { | |
return console.log('Тест 3 не пройден - пришли неправильные данные'); | |
} | |
console.log('==== Тест 3 пройден успешно ===='); | |
}, 'myNumber'); | |
} | |
main(); | |
test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment