Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if parameter is number before Number.parse #191

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/specs/parameters.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

## Custom Parameters in steps

* This step uses a custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
* Convert custom parameter of type Person and value "{\"name\":\"John\",\"age\":30}"
* Check strings with numbers for example "3 % 4" is correct
6 changes: 5 additions & 1 deletion e2e/tests/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export default class Parameter {
assert.strictEqual(original.trim(), expected);
}

@Step("This step uses a custom parameter of type Person and value <person>")
@Step("Convert custom parameter of type Person and value <person>")
public async validatePerson(person: Person) {
assert.strictEqual(person.name, "John");
assert.strictEqual(person.age, 30);
assert.ok(person.isAdult());
}
@Step("Check strings with numbers for example <value> is correct")
async checkStringConversion(value: string) {
assert.strictEqual(value, "3 % 4");
}
}
7 changes: 5 additions & 2 deletions gauge-ts/src/processors/params/PrimitiveParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class PrimitiveParser implements ParameterParser {
}

private convertToNumber(value: string): number | undefined {
const num = Number.parseFloat(value);
return Number.isNaN(num) ? undefined : num;
if (value.trim() === "") {
return undefined;
}
const num = Number(value);
return Number.isFinite(num) ? num : undefined;
}

private convertToBoolean(value: string): boolean | undefined {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading