Как мне написать спецификацию для конкретной функции в Жасмин? - PullRequest
0 голосов
/ 09 мая 2018

Мне нужно написать спецификацию для следующей функции в Жасмин.

export function getComponent<T>(ele: HTMLElement, comp: string): T {
    let instance: T;
    for (let i = 0; i < (<DomElements>(ele as HTMLElement)).ej2_instances.length; i++) {
        instance = <T>(ele as DomElements).ej2_instances[i];
        let compName: string = (instance as { getModuleName: () => string } & T).getModuleName();
        if (comp === compName) {
            return instance;
        }
    } 
    return undefined;
}

Я попробовал следующее, но это не сработало.

describe('getcomponent function', (): void => {
    let instance: string;
    let componentname: string;
    function test(instance, componentname) {
        it('if statement', function () {
            expect(instance).toEqual(componentname)
        });
    }
    for (let i = 0; i < instance.length; i++) {
        test(instance[i], componentname[i])
    }
})

1 Ответ

0 голосов
/ 09 мая 2018

вы можете использовать этот код, он поможет вам получить решение

describe("getcomponent funtion", function () {
    it("if statement", function () {
        let comp: any= {ej2_instances:[new Touch()]};
        expect(getComponent(comp, 'touch') instanceof Touch).toBe(true);
    });
    it("else statement", function () {
        let comps: any= {ej2_instances:[new Touch()]};
        expect(getComponent(comps, 'button') instanceof Touch).toBe(true);
    });
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...