【发布时间】:2018-03-14 00:21:20
【问题描述】:
在学习对我的 expo/react-native 应用程序进行单元测试时遇到问题。我将如何在此类中对向商店添加交易进行单元测试:
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,但我不知道如何以这样的方式将假(tx, result) 放入executeSql 的嵌套函数中。
【问题讨论】:
标签: javascript sqlite unit-testing jestjs expo