{"id":15714496,"url":"https://github.com/tatilimongi/jest_basics","last_synced_at":"2026-04-22T16:33:29.082Z","repository":{"id":257684196,"uuid":"859026827","full_name":"tatilimongi/Jest_Basics","owner":"tatilimongi","description":"This repository contains basic JavaScript functions with Jest unit tests, covering operations like addition, subtraction, and string manipulation, along with error handling.","archived":false,"fork":false,"pushed_at":"2024-09-18T00:37:21.000Z","size":51,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T19:46:58.971Z","etag":null,"topics":["automation-testing","error-handling","functions","javascript","jest","tdd-javascript","unit-test"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tatilimongi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-18T00:25:00.000Z","updated_at":"2024-09-18T00:40:19.000Z","dependencies_parsed_at":"2024-09-18T04:37:03.613Z","dependency_job_id":null,"html_url":"https://github.com/tatilimongi/Jest_Basics","commit_stats":null,"previous_names":["tatilimongi/jest_basics"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatilimongi%2FJest_Basics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatilimongi%2FJest_Basics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatilimongi%2FJest_Basics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tatilimongi%2FJest_Basics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tatilimongi","download_url":"https://codeload.github.com/tatilimongi/Jest_Basics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246372503,"owners_count":20766626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation-testing","error-handling","functions","javascript","jest","tdd-javascript","unit-test"],"created_at":"2024-10-03T21:37:40.014Z","updated_at":"2026-04-22T16:33:24.062Z","avatar_url":"https://github.com/tatilimongi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Functions with Unit Tests using Jest\n\nThis repository contains a set of basic JavaScript functions, along with unit tests written using **Jest** to ensure these functions behave as expected.\n\n## File Structure\n\n### 1. `funcoes.js`\n\nThis file contains several simple functions that perform basic mathematical operations and string manipulations:\n\n- `somar(x, y)`: Returns the sum of two numbers.\n- `obterNumeros()`: Returns an array of predefined numbers.\n- `validarNumeroPositivo(num)`: Checks if a number is positive, throwing an error if it's negative.\n- `subtrair(x, y)`: Returns the subtraction of two numbers.\n- `multiplicar(x, y)`: Returns the multiplication of two numbers.\n- `divisao(x, y)`: Returns the division of two numbers, throwing an error if the divisor is zero.\n- `ehPar(num)`: Checks if a number is even.\n- `contarPalavras(frase)`: Returns the number of words in a string.\n\n### 2. `funcoes.test.js`\n\nThis file contains the unit tests for the functions above, using the **Jest** framework. Each function is tested with different scenarios to ensure they return the expected results or throw errors appropriately.\n\n## How to Run the Tests\n\n1. Make sure you have **Node.js** installed on your machine.\n2. Clone this repository.\n3. Install the dependencies (Jest) by running:\n\n```bash\nnpm install\n```\n\n4. To run the tests, use the command:\n\n```bash\nnpm test\n```\n\n## Implemented Tests\n\nThe tests cover the following cases:\n\n- Sum of two numbers.\n- Verification of an array of numbers returned by the `obterNumeros` function.\n- Checking elements within the array.\n- Validation of positive numbers and error throwing.\n- Comparison of `undefined`, `null`, and boolean (`truthy`, `falsy`) values.\n- Numeric comparisons (`greaterThan`, `lessThan`).\n- Subtraction, multiplication, and division of numbers.\n- Error checking when dividing by zero.\n- Checking if a number is even.\n- Counting words in a sentence.\n\n## Example Tests\n\n```javascript\ntest(\"Should correctly add two numbers\", () =\u003e {\n  expect(somar(2, 3)).toBe(5);\n});\n\ntest(\"Should throw an error when trying to divide a number by zero\", () =\u003e {\n  expect(() =\u003e divisao(5, 0).toThrow(\"Cannot divide by zero\"));\n});\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Contributions\n\nContributions are welcome! Feel free to fork this repository and open a pull request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftatilimongi%2Fjest_basics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftatilimongi%2Fjest_basics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftatilimongi%2Fjest_basics/lists"}