0
내 엑스포/반응 네이티브 앱을 단위 테스트하는 데 어려움이 있습니다. 이 클래스의 상점에 트랜잭션을 추가하는 단위 테스트는 어떻게됩니까?유토피아에서 expo sqlite 호출로 단위 테스트 클래스
export default class TransactionsStore {
@observable _transactions = [];
constructor(rootStore) {
this.rootStore = rootStore;
}
@action addTransaction(t, db) {
db.transaction(tx => {
tx.executeSql(
'INSERT INTO transactions (categoryId, description, date, amount, currencyCode, isReported) VALUES (?,?,?,?,?,?);',
[t.category, t.description, t.date, t.amount, t.currency.code, t.report],
(tx, result) => { t.id = result.insertId; }
);
}, error => alert(error));
this.reloadTransactions(db);
}
}
콜백 내의 모든 콜백은 매우 어렵습니다. 나는 어떻게 든 db.transaction
을 모의해야만한다고 생각하지만, executeSql
의 그 중첩 된 기능에 위조를주는 그런 방법으로 그것을하는 방법을 볼 수는 없다. (tx, result)
.