{"id":17187355,"url":"https://github.com/jareguo/qunit-assert-callback","last_synced_at":"2025-03-25T03:54:15.934Z","repository":{"id":19760648,"uuid":"23018210","full_name":"jareguo/qunit-assert-callback","owner":"jareguo","description":"A QUnit assert plugin to test callback. You can easily assert that the callback can (only) be called at the correct moment.","archived":false,"fork":false,"pushed_at":"2014-09-27T09:20:59.000Z","size":196,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T04:27:20.227Z","etag":null,"topics":["qunit"],"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/jareguo.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}},"created_at":"2014-08-16T13:10:34.000Z","updated_at":"2017-12-16T08:40:49.000Z","dependencies_parsed_at":"2022-08-31T17:02:03.237Z","dependency_job_id":null,"html_url":"https://github.com/jareguo/qunit-assert-callback","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jareguo%2Fqunit-assert-callback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jareguo%2Fqunit-assert-callback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jareguo%2Fqunit-assert-callback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jareguo%2Fqunit-assert-callback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jareguo","download_url":"https://codeload.github.com/jareguo/qunit-assert-callback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245394770,"owners_count":20608123,"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":["qunit"],"created_at":"2024-10-15T01:06:07.892Z","updated_at":"2025-03-25T03:54:15.908Z","avatar_url":"https://github.com/jareguo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QUnit callback assertion plugin\n\nA QUnit assert plugin to test sync callback. You can easily assert that the callback can (only) be called at the correct moment, and has the correct times.\n\n## Usage\n\n```js\nvar obj;\n\n// Create and return a new callback wrapper for handling assertion.\nobj.callback = assert.Callback(callbackFunction_opt);\n\n// By default, the callback is not allowed to call unless you call its enable method first.\n// You can enable and disable repeatedly.\nobj.callback.enable();\nobj.callback.disable(msgWhenDisabled_opt);\n\n// Expect the callback to be called any times you wish\nobj.callback.expect(count, message_opt);\n\n// Expect the callback to be called one time, and then reset the time to 0\n// so that you can do this repeatedly.\nobj.callback.once(message_opt);\n```\n\n## Examples\n\n### Make Assertion failed if called\n\n```js\nobj.onDown = assert.Callback();          // disabled by default\nvar foo = function() { obj.onDown() };\n\nfoo();    // Assertion failed! onDown should not be called in foo!\n```\n\n### Assert callback called\n\n```js\nobj.onDown = assert.Callback().enable(); // enabled this time ;)\nvar foo = function() { obj.onDown() };\n\nfoo();   // No error this time ;)\nobj.onDown.once('onDown should be called once');   // Assertion succeeded!\n```\n\n### Expect the callback to be called any times you wish\n\n```js\nobj.onDown = assert.Callback().enable();\nvaf down = function() { obj.onDown() };\n\ndown();\nobj.onDown.expect(1);    // Okey!\ndown();\nobj.onDown.expect(2);    // Okey!\ndown();\ndown();\nobj.onDown.expect(4);    // Okey!\n```\n\n### Disable the callback if you think it should not be called anymore.\n\n```js\nobj.onDown = assert.Callback().enable();\nvar foo = function() { obj.onDown() };\n\nfoo();\nobj.onDown.once('onDown should be called')\n          .disable('onDown should not be called from now on');\nfoo();       // Assertion failed: onDown should not be called from now on\nobj.onDown.enable();\nfoo();\nobj.onDown.once('onDown should be called again')\n          .disable('onDown should not be called anymore');\nfoo();       // Assertion failed: onDown should not be called anymore\n```\n\n### You can register a callback when the wrapper is called.\n\n```js\n// callback 1\nobj.onUp = assert.Callback().enable();\n// callback 2\nobj.onDown = assert.Callback( function(val) {\n    equal(this, obj,     'assert this');\n    equal(val,  520,     'assert argument');\n    equal(obj.onUp.calledCount, 1, 'onUp should be called before onDown!');\n}).enable();             // dont forget enable!\nobj.upAndDown = function() { obj.onUp(); obj.onDown(520) };\nobj.upAndDown();\nobj.onDown.expect(1, 'onDown should be called once!');    // Okey!\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjareguo%2Fqunit-assert-callback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjareguo%2Fqunit-assert-callback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjareguo%2Fqunit-assert-callback/lists"}