Hellosだから私はredux非同期アクションのテストを書いているので、オブジェクトがobjet配列に存在すると主張しようとしています。予想される副作用が発生しても(ファイアベースにデータを保存する)正常に実行するためのテスト期待値jsをKarmaスイートで使用してJSONオブジェクトの存在をアサートしようとしています
ここは私のテストです。
describe('Async Actions',() => {
it('should upload supplier and dispatch ADD_SUPPLIER', (done)=> { /*Let Mocha know that this is asnyc test*/
//mock a store
const store = createMockStore({});
//test supplier
var testSupplier = {
name: "new supplier",
fact_sheet: "fact sheet",
liability_sheet: "liability sheet",
group: "group",
service_lines: null,
policies: null,
rate_periods: null,
rate_costs: null,
contracts: null,
cancellation_terms: null,
deposit_terms: null,
commission: 22,
creation_date: moment().unix(),
country: "SA",
region: "Capetown",
email: "[email protected]",
telephone: "2797179",
website: "ww.ww.ww",
category: "cat",
rating: 100
};
//Do the async action
store.dispatch(actions.startAddSupplier(testSupplier.name, testSupplier.fact_sheet, testSupplier.liability_sheet, testSupplier.group,
testSupplier.commission, testSupplier.country, testSupplier.region, testSupplier.email, testSupplier.telephone, testSupplier.website, testSupplier.category, testSupplier.rating)).then(
() => {
/*Assertions*/
const actions = store.getActions(); //returns array of all actions fired on store
expect(actions).toInclude({
type: 'ADD_SUPPLIER'
});
/*done to show test is done*/
done();
}).catch(done);//if done is called with args it is assumed the test has failed
});
});
、これは私が何か間違ったことをやっている私は、エラーを見つけることにいかなる助けをいただければ幸いかなり確信している私はエラーとしてコンソールに何を得る
FAILED TESTS:
Actions
Supplier Actions
Async Actions
✖ should upload supplier and dispatch ADD_SUPPLIER
Chrome 53.0.2785 (Mac OS X 10.12.0)
Error: Expected [ { supplier: { cancellation_terms: null, category: 'cat', commission: 22, contracts: null, country: 'SA', creation_date: 1476087460, deposit_terms: null, email: '[email protected]', fact_sheet: 'fact sheet', group: 'group', id: '-KThemyhqrmDHuF_PV2H', liability_sheet: 'liability sheet', name: 'new supplier', policies: null, rate_costs: null, rate_periods: null, rating: 100, region: 'Capetown', service_lines: null, telephone: '2797179', website: 'ww.ww.ww' }, type: 'ADD_SUPPLIER' }, { key: '-KThemyhqrmDHuF_PV2H', type: 'SET_CURR_SUPPLIER' } ] to include { type: 'ADD_SUPPLIER' }
at Object.assert [as default] (eval at <anonymous> (/Users/zacck/Documents/www/jtx/app/tests/actions/actions.test.jsx:1231:2), <anonymous>:20:9)
at Expectation.toInclude (eval at <anonymous> (/Users/zacck/Documents/www/jtx/app/tests/actions/actions.test.jsx:1129:2), <anonymous>:190:26)
at eval (eval at <anonymous> (/Users/zacck/Documents/www/jtx/app/tests/actions/actions.test.jsx:47:2), <anonymous>:129:42)
です。
あなたのテスト 'testSupplier'には' id'プロパティがありません。 –