如何检查对象数组中的值

时间:2019-04-01 14:18:10

标签: javascript angular karma-jasmine

我正忙于茉莉花单元测试。但是我得到了错误。我在使用数组中的更多值时遇到了一些问题。我不明白。

我将其作为单元测试代码:

WEB-INF/classes/beans.xml

但是后来我得到这个错误:

  component.portfolio = {
            learningPath: [
                {
                    id: '2345',
                    metaLines: ['sbu tekst', '29 maart 2019'],
                    title: 'mock name',
                    titleLink: `${learningPathDetailsLink}/2345`,

                },
                {
                    id: '23567',
                    metaLines: ['sbu tekst', '1 april 2019'],
                    title: 'mock name',
                    titleLink: `${learningPathDetailsLink}/23567`,

                },


            ],
        } as any;

        // Assert
        expect(component.cards).toEqual([
            new CardModel({ id: '2345', metaLines: ['sbu tekst', '29 maart 2019'], title: 'mock name', titleLink: `${learningPathDetailsLink}/2345` }),
            new CardModel({ id: '23567', metaLines: ['sbu tekst', '1 april 2019'], title: 'mock name', titleLink: `${learningPathDetailsLink}/23567` }),
        ]);
        expect(formatPipeSpy.calls.argsFor(0)).toEqual(['30 maart 2019', resources.begindatumTitel]);
        expect(formatPipeSpy.calls.argsFor(1)).toEqual(['30 maart 2019', resources.afrondDatumTitel]);

我真的不明白这一点。因为什么地方出了错:

Expected $[0].metaLines[0] = undefined to equal 'sbu tekst'.
Expected $[0].metaLines[1] = undefined to equal '29 maart 2019'.
Expected $[0].title = undefined to equal 'mock name'.
Expected $[0].titleLink = 'undefined/2345' to equal 'test/learningpath-details/2345'.
Expected $[1].metaLines[0] = undefined to equal 'sbu tekst'.
Expected $[1].metaLines[1] = undefined to equal '1 april 2019'.
Expected $[1].title = undefined to equal 'mock name'.
Expected $[1].titleLink = 'undefined/23567' to equal 'test/learningpath-details/23567'.
Error: Expected $[0].metaLines[0] = undefined to equal 'sbu tekst'.
Expected $[0].metaLines[1] = undefined to equal '29 maart 2019'.
Expected $[0].title = undefined to equal 'mock name'.
Expected $[0].titleLink = 'undefined/2345' to equal 'test/learningpath-details/2345'.
Expected $[1].metaLines[0] = undefined to equal 'sbu tekst'.
Expected $[1].metaLines[1] = undefined to equal '1 april 2019'.
Expected $[1].title = undefined to equal 'mock name'.
Expected $[1].titleLink = 'undefined/23567' to equal 'test/learningpath-details/23567'.
    at <Jasmine>
    at UserContext.<anonymous> (http://localhost:9890/_karma_webpack_/webpack:/src/components/src/portfolio/portfolio-details/portfolio-details.component.spec.ts:116:33)
    at UserContext.<anonymous> (http://localhost:9890/_karma_webpack_/webpack:/E:/Projects/VLR/Web/vlrworkspace/node_modules/zone.js/dist/zone-testing.js:1429:1)
    at ZoneDelegate.push.../../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9890/_karma_webpack_/webpack:/E:/Projects/VLR/Web/vlrworkspace/node_modules/zone.js/dist/zone.js:391:1)
Expected $[0] = undefined to equal '30 maart 2019'.

这是两个值吗?

0 个答案:

没有答案