{"id":18616023,"url":"https://github.com/bjoern-hempel/js-testing-framework","last_synced_at":"2025-11-03T05:30:22.116Z","repository":{"id":110076556,"uuid":"135948030","full_name":"bjoern-hempel/js-testing-framework","owner":"bjoern-hempel","description":"This is a small testing framework to make test driven development and unit testing easy.","archived":false,"fork":false,"pushed_at":"2018-09-01T14:48:44.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T03:13:14.580Z","etag":null,"topics":["javascript","test-driven-development","unit-testing"],"latest_commit_sha":null,"homepage":null,"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/bjoern-hempel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2018-06-03T23:17:28.000Z","updated_at":"2018-09-01T14:48:46.000Z","dependencies_parsed_at":"2023-04-01T15:48:28.052Z","dependency_job_id":null,"html_url":"https://github.com/bjoern-hempel/js-testing-framework","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoern-hempel%2Fjs-testing-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoern-hempel%2Fjs-testing-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoern-hempel%2Fjs-testing-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjoern-hempel%2Fjs-testing-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjoern-hempel","download_url":"https://codeload.github.com/bjoern-hempel/js-testing-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239412487,"owners_count":19634016,"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":["javascript","test-driven-development","unit-testing"],"created_at":"2024-11-07T03:33:49.061Z","updated_at":"2025-11-03T05:30:22.071Z","avatar_url":"https://github.com/bjoern-hempel.png","language":"JavaScript","readme":"# A Javascript testing framework\n\nThis is a small testing framework to make test driven development and unit testing easy.\n\n## 0. Introduction\n\n### 0.1 Add this library as git submodule\n\n```bash\nuser$ cd /your/root/project/path\nuser$ git submodule add https://github.com/bjoern-hempel/js-testing-framework.git vendor/js-testing-framework\nuser$ git commit -m \"add the js-testing-framework library as submodule\" .gitmodules vendor/js-testing-framework\nuser$ git push\n```\n\n### 0.2 Update submodule to the latest master version\n\n```bash\nuser$ cd /your/root/project/path\nuser$ cd vendor/js-testing-framework\nuser$ git pull origin master\nuser$ cd ../..\nuser$ git add vendor/js-testing-framework\nuser$ git commit -m \"update the js-testing-framework library submodule\" vendor/js-testing-framework\nuser$ git push\n```\n\n## 1. Usage - Basic Examples\n\n### 1.1 Set options (optional)\n\n```javascript\nJsTest.setOptions({\n    outputConsole: true,\n    outputDocument: true,\n    outputId: 'test-output',\n    outputEntryStyle: {\n        fontSize: '10px',\n        fontStyle: 'italic',\n        margin: 0\n    },\n    outputSectionStyle: {\n        border: '1px solid grey',\n        padding: '10px',\n        margin:  '10px',\n        backgroundColor: '#f0f0f0'\n    }\n});\n```\n\n### 1.2 Basic Test Example\n\n```javascript\nvar test = new JsSuccessTest([\n    'check 1 + 2',\n    new JsTestTestFunction(function () {\n        var sum = 1 + 2;\n        return JsTest.equalInteger(sum, 3);\n    })\n]);\n\nJsTest.startTests('Simple tests.', test);\n```\n\nThe test returns:\n\n```javascript\n──────────────────────────\nStart test \"Simple tests.\"\n──────────────────────────\n \n  1) Running success test \"check 1 + 2\" .\n     → Test succeeded (0.1 ms).\n \n──────────────────────────────────────────────────────────────\nRESULT\n-\u003e All test succeeded (0.7 ms) [success: 1; error: 0; all: 1].\n──────────────────────────────────────────────────────────────\n```\n\n### 1.3 Multiple Test Example\n\n```javascript\nvar tests = [\n    new JsSuccessTest(\n        'check 1 + 2',\n        new JsTestTestFunction(function () {\n            var sum = 1 + 2;\n            return JsTest.equalInteger(sum, 3);\n        })\n    ),\n    new JsSuccessTest(\n        'check 10 - 2',\n        new JsTestTestFunction(function () {\n            var difference = 10 - 2;\n            return JsTest.equalInteger(difference, 8);\n        })\n    )\n];\n\nJsTest.startTests('Simple tests.', tests);\n```\n\nThe test returns:\n\n```javascript\n──────────────────────────\nStart test \"Simple tests.\"\n──────────────────────────\n \n  1) Running success test \"check 1 + 2\" .\n     → Test succeeded (0.1 ms).\n  2) Running success test \"check 10 - 2\" .\n     → Test succeeded (0.1 ms).\n \n────────────────────────────────────────────────────────────\nRESULT\n-\u003e All test succeeded (1 ms) [success: 2; error: 0; all: 2].\n────────────────────────────────────────────────────────────\n```\n\n### 1.4 Error Test Example\n\nUse the error test (JsErrorTest) if you expect an exception as a test result:\n\n```javascript\nvar test = new JsErrorTest(\n    'check 1 + 2',\n    100,\n    new JsTestTestFunction(function () {\n        var sum = 1 + 2;\n        throw new Error('100 - Simple Error test');\n        return JsTest.equalInteger(sum, 3);\n    })\n);\n\nJsTest.startTests('Simple error test.', test);\n```\n\nThe test returns\n\n```javascript\n───────────────────────────────\nStart test \"Simple error test.\"\n───────────────────────────────\n \n  1) Running error test \"check 1 + 2\" (Code: 100).\n     → Test succeeded (6 ms).\n \n──────────────────────────────────────────────────────────────\nRESULT\n-\u003e All test succeeded (6.8 ms) [success: 1; error: 0; all: 1].\n──────────────────────────────────────────────────────────────\n```\n\n### 1.5 Summary of all tests within a function\n\nUse a function container to summerize all tests within a function instead of a JsTest Array:\n\n```javascript\nvar tests = function() {\n    new JsSuccessTest(\n        'check 1 + 2',\n        new JsTestTestFunction(function () {\n            var sum = 1 + 2;\n            return JsTest.equalInteger(sum, 3);\n        })\n    );\n\n    new JsSuccessTest(\n        'check 10 - 2',\n        new JsTestTestFunction(function () {\n            var difference = 10 - 2;\n            return JsTest.equalInteger(difference, 8);\n        })\n    );\n};\n\nJsTest.startTests('Simple tests.', tests);\n```\n\nThe test returns:\n\n```javascript\n──────────────────────────\nStart test \"Simple tests.\"\n──────────────────────────\n\n  1) Running success test \"check 1 + 2\" .\n     → Test succeeded (0.1 ms).\n  2) Running success test \"check 10 - 2\" .\n     → Test succeeded (0 ms).\n\n──────────────────────────────────────────────────────────────\nRESULT\n-\u003e All test succeeded (1.5 ms) [success: 2; error: 0; all: 2].\n──────────────────────────────────────────────────────────────\n```\n\n### 1.6 Use your own exception class\n\n```javascript\n/**\n * Own js test exception class.\n */\nclass MyOwnException {\n    constructor(code, message) {\n        this.code = code;\n        this.message = message;\n    }\n}\n\n/**\n * Test function\n */\nvar test = new JsErrorTest(\n    new MyOwnException(100, 'check 10 - 11'),\n    new JsTestTestFunction(function () {\n        var minuend = 10;\n        var subtrahend = 11;\n\n        if (subtrahend \u003e minuend) {\n            throw new MyOwnException(100, 'The subtrahend is bigger than the minuend.');\n        }\n\n        var difference = minuend - subtrahend;\n        return JsTest.equalInteger(difference, 8);\n    })\n);\n\nJsTest.startTests('Simple tests.', test);\n```\n\nThe test returns:\n\n```javascript\n──────────────────────────\nStart test \"Simple tests.\"\n──────────────────────────\n\n  1) Running error test \"check 10 - 11\" (Code: 100).\n     → Test succeeded: \"The subtrahend is bigger than the minuend.\" (0.1 ms).\n\n──────────────────────────────────────────────────────────────\nRESULT\n-\u003e All test succeeded (0.8 ms) [success: 1; error: 0; all: 1].\n──────────────────────────────────────────────────────────────\n```\n\n### 1.7 Test different properties\n\n```javascript\nvar test = new JsSuccessTest([\n    'vector add test',\n    new JsTestTestFunction(function () {\n        var vector1 = [1, 2];\n        var vector2 = [2, 3];\n\n        var addedVector = vector1.map(function (value, index) {\n            return value + vector2[index];\n        });\n\n        return (\n            JsTest.equalInteger(addedVector.length, 2) \u0026\u0026\n            JsTest.equalArrayValues(addedVector, [3, 5])\n        );\n    })\n]);\n\nJsTest.startTests('Simple tests.', test);\n```\n\nThe test returns:\n\n```javascript\n\n──────────────────────────\nStart test \"Simple tests.\"\n──────────────────────────\n\n  1) Running success test \"vector add test\" .\n     → Test succeeded (3 ms).\n\n──────────────────────────────────────────────────────────────\nRESULT\n-\u003e All test succeeded (4.1 ms) [success: 1; error: 0; all: 1].\n──────────────────────────────────────────────────────────────\n```\n\n#### 1.7.1 If one property check fails\n\n```javascript\nvar test = new JsSuccessTest([\n    'vector add test',\n    new JsTestTestFunction(function () {\n        var vector1 = [1, 2];\n        var vector2 = [2, 3];\n\n        var addedVector = vector1.map(function (value, index) {\n            return value + vector2[index];\n        });\n\n        return (\n            JsTest.equalInteger(addedVector.length, 2) \u0026\u0026\n            JsTest.equalArrayValues(addedVector, [3, 6])\n        );\n    })\n]);\n\nJsTest.startTests('Simple tests.', test);\n```\n\nThe test returns:\n\n```javascript\n──────────────────────────\nStart test \"Simple tests.\"\n──────────────────────────\n\n  1) Running success test \"vector add test\" .\n     The 1. equalArrayValues test failed.\n     → Test failed (0.6 ms).\n\n─────────────────────────────────────────\nRESULT\n-\u003e At least on test failed (1.6 ms) [1/1]\n─────────────────────────────────────────\n```\n\n\n## A. Authors\n\n* Björn Hempel \u003cbjoern@hempel.li\u003e - _Initial work_ - [https://github.com/bjoern-hempel](https://github.com/bjoern-hempel)\n\n## B. Licence\n\nThis tutorial is licensed under the MIT License - see the [LICENSE.md](/LICENSE.md) file for details\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjoern-hempel%2Fjs-testing-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjoern-hempel%2Fjs-testing-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjoern-hempel%2Fjs-testing-framework/lists"}