generated from freeCodeCamp/template
-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create a JS helpers class (#190)
* feat: create js helpers * capture arrow functions * make everything more readable
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import jsTestValues from "../__fixtures__/curriculum-helpers-javascript"; | ||
|
||
import { getFunctionParams } from "../index"; | ||
|
||
const { functionDeclaration, constFunction, letFunction, arrowFunction } = | ||
jsTestValues; | ||
|
||
describe("js-help", () => { | ||
describe("getFunctionArgs", () => { | ||
it("gets arguments from function declarations", function () { | ||
const parameters = getFunctionParams(functionDeclaration); | ||
expect(parameters[0].name).toBe("param1"); | ||
expect(parameters[1].defaultValue).toBe("default"); | ||
expect(parameters[1].name).toBe("param2"); | ||
expect(parameters[2].name).toBe("param3"); | ||
}); | ||
it("gets arguments from const function variables", function () { | ||
const parameters = getFunctionParams(constFunction); | ||
expect(parameters[0].name).toBe("param1"); | ||
expect(parameters[1].defaultValue).toBe("default"); | ||
expect(parameters[1].name).toBe("param2"); | ||
expect(parameters[2].name).toBe("param3"); | ||
}); | ||
it("gets arguments from let function variables", function () { | ||
const parameters = getFunctionParams(letFunction); | ||
expect(parameters[0].name).toBe("param1"); | ||
expect(parameters[1].defaultValue).toBe("default"); | ||
expect(parameters[1].name).toBe("param2"); | ||
expect(parameters[2].name).toBe("param3"); | ||
}); | ||
it("gets arguments from arrow functions", function () { | ||
const parameters = getFunctionParams(arrowFunction); | ||
expect(parameters[0].name).toBe("name"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters