0
私はinit関数のためのユニットテストを書くことをしようとしていると私は私がテストでcollectionReport.init()
を呼び出していますエラーを取得しています....init()関数をジャスミンでユニットテストするにはどうすればよいですか?
TypeError: undefined is not an object
これは私がテストしようとしているコードです。 ...
class CollectionsReport {
constructor({ editCollectionsId, hasCollections}) {
this.editCollectionsId = editCollectionsId;
this.hasCollections = hasCollections
}
init({ id, name }) {
this.id = id;
this.name = name;
// need to test this
if (this.hasCollections) {
this.collection = this.collections.find(c => c.staticId === 'CAR-COLLECTION');
}
}
そして、これはこれまでのところ
describe('CollectionsReport',() => {
const collectionArgs = {
editCollectionsId: jasmine.createSpy(),
hasCollections: false,
};
const collections = [
{
id: 1,
name: 'foo',
staticId: 'CAR-COLLECTIONS',
},
{
id: 2,
name: 'bar',
staticId: 'TRUCK-COLLECTIONS',
},
];
let collectionReport;
beforeEach(() => {
collectionReport = new CollectionsReport(collectionArgs);
});
describe('.init()',() => {
it('should test hasCollections',() => {
collectionReport.init();
//test this.hasCollections here
});
});
});
私のテストである私は、その混乱確信しているので、それを修正し、改善する方法についてコメントしてください。ユニットテストのために新しい人に大変感謝しています。
'CollectionsReport'がオブジェクトを期待していますが、配列 –
おかげで、私を送っていますオブジェクトであるcollectionArgsを送信しています。私は配列を送っているのが分かりますか? –
それはプレーンなJavaスクリプトか角度ですか? – Aravind