2

I have this function:

this.checkButton = function (buttonName, element, expectedPresent, expectedEnabled) {
    var enabledCheck = expectedEnabled ? "enabled" : "disabled";
    it('Find a ' + buttonName + ' button and check it is ' + enabledCheck, function () {
        expect(element.isPresent()).toBe(expectedPresent);
        expect(element.isEnabled()).toBe(expectedEnabled);
    });
}

Is there a way I can make this so that if the function is called without the last two parameters then those parameters will both default to true?

2 Answers2

2

Compare the parameters to undefined to know if they are present:

    this.checkButton = function (buttonName, element, expectedPresent, expectedEnabled) {

        if(expectedPresent === undefined) {
            expectedPresent = true;
        }
        if(expectedEnabled === undefined) {
            expectedEnabled = true;
        }
        var enabledCheck = expectedEnabled ? "enabled" : "disabled";
        it('Find a ' + buttonName + ' button and check it is ' + enabledCheck, function () {
            expect(element.isPresent()).toBe(expectedPresent);
            expect(element.isEnabled()).toBe(expectedEnabled);
        });
    }
Pascal Le Merrer
  • 5,883
  • 20
  • 35
0

If I understood what you want.

Try to say in starting of function.

expectedPresent = (expectedPresent==undefined) ? true : expectedPresent;
expectedEnabled = (expectedEnabled==undefined) ? true : expectedEnabled;

I hope this helps.

Mritunjay
  • 25,338
  • 7
  • 55
  • 68