diff --git a/e2e/specs/parameters.spec b/e2e/specs/parameters.spec index a748d97..f20f0f2 100644 --- a/e2e/specs/parameters.spec +++ b/e2e/specs/parameters.spec @@ -6,5 +6,5 @@ ## Custom Parameters in steps -* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" -* This step checks if strings with numbers for example "3 % 4" is correct +* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}" +* Check strings with numbers for example "3 % 4" is correct diff --git a/e2e/tests/parameter.ts b/e2e/tests/parameter.ts index 4c7f1b2..924d28e 100644 --- a/e2e/tests/parameter.ts +++ b/e2e/tests/parameter.ts @@ -8,16 +8,14 @@ export default class Parameter { assert.strictEqual(original.trim(), expected); } - @Step("This step uses a custom parameter of type Person and value ") + @Step("Convert custom parameter of type Person and value ") public async validatePerson(person: Person) { assert.strictEqual(person.name, "John"); assert.strictEqual(person.age, 30); assert.ok(person.isAdult()); } - @Step( - "This step checks if strings with numbers for example is correct", - ) - async setFilter(value: string) { + @Step("Check strings with numbers for example is correct") + async checkStringConversion(value: string) { assert.strictEqual(value, "3 % 4"); } } diff --git a/gauge-ts/src/processors/params/PrimitiveParser.ts b/gauge-ts/src/processors/params/PrimitiveParser.ts index fee797e..cc19c71 100644 --- a/gauge-ts/src/processors/params/PrimitiveParser.ts +++ b/gauge-ts/src/processors/params/PrimitiveParser.ts @@ -27,12 +27,11 @@ export class PrimitiveParser implements ParameterParser { } private convertToNumber(value: string): number | undefined { - const trimmedValue = value.trim(); - if (/^-?\d+(\.\d+)?$/.test(trimmedValue)) { - const num = Number.parseFloat(trimmedValue); - return Number.isFinite(num) ? num : undefined; + if (value.trim() === "") { + return undefined; } - return undefined; + const num = Number(value); + return Number.isFinite(num) ? num : undefined; } private convertToBoolean(value: string): boolean | undefined {