Skip to content

Commit

Permalink
test(graphql): get number of arguments util
Browse files Browse the repository at this point in the history
create additional tests to ensure the arguments count is correct for all types of functions with and without body
  • Loading branch information
thiagomini committed Oct 25, 2022
1 parent 93cbbd7 commit 2a06e5e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/graphql/tests/utils/get-number-of-arguments.util.spec.ts
Expand Up @@ -23,6 +23,17 @@ describe('getNumberOfArguments', () => {
expect(getNumberOfArguments(oneArgFunction)).toBe(1);
});

it('should return 1 for a 1-argument function with body', () => {
function oneArgFunction(_arg1: any) {
if (1 == +'2') {
return false;
}

return true;
}
expect(getNumberOfArguments(oneArgFunction)).toBe(1);
});

it('should return 2 for a 2-argument function', () => {
function twoArgFunction(_arg1: any, _arg2: any) {}
expect(getNumberOfArguments(twoArgFunction)).toBe(2);
Expand Down Expand Up @@ -92,8 +103,24 @@ describe('getNumberOfArguments', () => {
class TestStaticClass {
static methodZeroArguments() {}

static methodZeroArgumentsWithBody() {
if (1 == +'2') {
return false;
}

return true;
}

static methodOneArgument(_arg: any) {}

static methodOneArgumentWithBody(_arg: any) {
if (1 == +'2') {
return false;
}

return true;
}

static methodTwoArguments(_arg1: any, _arg2: any) {}

static methodTwoArgumentsOneOptional(_arg1: any, _arg2 = ['raw']) {}
Expand All @@ -103,10 +130,22 @@ describe('getNumberOfArguments', () => {
expect(getNumberOfArguments(TestStaticClass.methodZeroArguments)).toBe(0);
});

it('should return 0 for a 0-argument function with body', () => {
expect(
getNumberOfArguments(TestStaticClass.methodZeroArgumentsWithBody),
).toBe(0);
});

it('should return 1 for a 1-argument function', () => {
expect(getNumberOfArguments(TestStaticClass.methodOneArgument)).toBe(1);
});

it('should return 1 for a 1-argument function with body', () => {
expect(
getNumberOfArguments(TestStaticClass.methodOneArgumentWithBody),
).toBe(1);
});

it('should return 2 for a 2-argument function', () => {
expect(getNumberOfArguments(TestStaticClass.methodTwoArguments)).toBe(2);
});
Expand Down

0 comments on commit 2a06e5e

Please sign in to comment.