[英]Unit-testing Electron-React app with Jest, TypeError: Cannot match against 'undefined' or 'null'
[英]TypeError: Cannot match against 'undefined' or 'null'
碼
client.createPet(pet, (err, {name, breed, age}) => {
if (err) {
return t.error(err, 'no error')
}
t.equal(pet, {name, breed, age}, 'should be equivalent')
})
錯誤
client.createPet(pet, (err, {name, breed, age}) => {
^
TypeError: Cannot match against 'undefined' or 'null'.
為什么我收到此錯誤? 我對ES6的了解促使我假設只有在被解構的數組或對象或其子 undefined
或為null
才會出現此錯誤。
我不知道函數參數被用作匹配項。 如果它們是,那么為什么我試圖解構其中一個只是一個錯誤? (這不是undefined
或null
)。
只有在被解構的數組或對象或其子
undefined
或為null
才會出現此錯誤。
究竟。 在您的情況下,被解構的對象是undefined
或null
。 例如,
function test(err, {a, b, c}) {
console.log(err, a, b, c);
}
test(1, {a: 2, b: 3, c: 4});
// 1 2 3 4
test(1, {});
// 1 undefined undefined undefined
test(1);
// TypeError: Cannot match against 'undefined' or 'null'.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.