{"_id":"duck","_rev":"3013969","name":"duck","description":"Rich matchers inspired by Hamcrest. Useful for generating helpful assertion failure messages in tests.","dist-tags":{"latest":"0.1.12"},"maintainers":[{"name":"mwilliamson","email":""}],"time":{"modified":"2023-09-20T03:43:07.000Z","created":"2012-08-25T21:51:42.758Z","0.1.12":"2021-05-11T20:50:02.407Z","0.1.11":"2013-04-13T20:52:14.416Z","0.1.10":"2013-04-12T21:08:20.952Z","0.1.9":"2012-09-08T18:19:55.637Z","0.1.8":"2012-08-25T21:51:42.758Z"},"users":{},"author":{"name":"Michael Williamson","email":"mike@zwobble.org"},"repository":{"type":"git","url":"git+https://github.com/mwilliamson/duck.js.git"},"versions":{"0.1.12":{"name":"duck","version":"0.1.12","author":{"name":"Michael Williamson","email":"mike@zwobble.org"},"description":"Rich matchers inspired by Hamcrest. Useful for generating helpful assertion failure messages in tests.","license":"BSD","repository":{"type":"git","url":"git+https://github.com/mwilliamson/duck.js.git"},"keywords":["test","assert","matcher","assertThat"],"dependencies":{"underscore":"^1.13.1"},"devDependencies":{"nodeunit":"~0.8.0"},"gitHead":"6e342b5447b157dd265b1bba7bb915e2dfeb3560","bugs":{"url":"https://github.com/mwilliamson/duck.js/issues"},"homepage":"https://github.com/mwilliamson/duck.js#readme","_id":"duck@0.1.12","_nodeVersion":"12.18.3","_npmVersion":"6.14.6","_npmUser":{"name":"mwilliamson","email":"mike@zwobble.org"},"dist":{"shasum":"de7adf758421230b6d7aee799ce42670586b9efa","size":5161,"noattachment":false,"key":"/duck/-/duck-0.1.12.tgz","tarball":"http://registry.cnpm.dingdandao.com/duck/download/duck-0.1.12.tgz"},"directories":{},"maintainers":[{"name":"mwilliamson","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/duck_0.1.12_1620766202149_0.5493228383397937"},"_hasShrinkwrap":false,"publish_time":1620766202407,"_cnpm_publish_time":1620766202407,"_cnpmcore_publish_time":"2021-12-16T21:21:47.383Z"},"0.1.11":{"name":"duck","version":"0.1.11","author":{"name":"Michael Williamson","email":"mike@zwobble.org"},"description":"Rich matchers inspired by Hamcrest. Useful for generating helpful assertion failure messages in tests.","license":"BSD","repository":{"type":"git","url":"https://github.com/mwilliamson/duck.js.git"},"keywords":["test","assert","matcher","assertThat"],"dependencies":{"underscore":"~1.4.4"},"devDependencies":{"nodeunit":"~0.8.0"},"readmeFilename":"README.md","_id":"duck@0.1.11","dist":{"shasum":"3adc1a3d2fbdd5879ffd3bda05ce0f69355e9093","size":5206,"noattachment":false,"key":"/duck/-/duck-0.1.11.tgz","tarball":"http://registry.cnpm.dingdandao.com/duck/download/duck-0.1.11.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"mwilliamson","email":"mike@zwobble.org"},"maintainers":[{"name":"mwilliamson","email":""}],"directories":{},"publish_time":1365886334416,"_hasShrinkwrap":false,"_cnpm_publish_time":1365886334416,"_cnpmcore_publish_time":"2021-12-16T21:21:47.636Z"},"0.1.10":{"name":"duck","version":"0.1.10","dependencies":{"underscore":"~1.4.4"},"devDependencies":{"nodeunit":"~0.8.0"},"_id":"duck@0.1.10","description":"ERROR: No README.md file found!","dist":{"shasum":"8f42930d192ab22d728e10eb3bdb7f1ccb50f440","size":2893,"noattachment":false,"key":"/duck/-/duck-0.1.10.tgz","tarball":"http://registry.cnpm.dingdandao.com/duck/download/duck-0.1.10.tgz"},"_from":".","_npmVersion":"1.2.14","_npmUser":{"name":"mwilliamson","email":"mike@zwobble.org"},"maintainers":[{"name":"mwilliamson","email":""}],"directories":{},"publish_time":1365800900952,"_hasShrinkwrap":false,"_cnpm_publish_time":1365800900952,"_cnpmcore_publish_time":"2021-12-16T21:21:47.855Z"},"0.1.9":{"name":"duck","version":"0.1.9","dependencies":{"underscore":"latest"},"devDependencies":{"nodeunit":"latest"},"_id":"duck@0.1.9","description":"ERROR: No README.md file found!","dist":{"shasum":"1041bf4b6b21eb63a19e87897ec4a8be8040ebf6","size":2874,"noattachment":false,"key":"/duck/-/duck-0.1.9.tgz","tarball":"http://registry.cnpm.dingdandao.com/duck/download/duck-0.1.9.tgz"},"_npmVersion":"1.1.59","_npmUser":{"name":"mwilliamson","email":"mike@zwobble.org"},"maintainers":[{"name":"mwilliamson","email":""}],"directories":{},"publish_time":1347128395637,"_hasShrinkwrap":false,"_cnpm_publish_time":1347128395637,"_cnpmcore_publish_time":"2021-12-16T21:21:48.070Z"},"0.1.8":{"name":"duck","version":"0.1.8","dependencies":{"underscore":"latest"},"devDependencies":{"nodeunit":"latest"},"_id":"duck@0.1.8","dist":{"shasum":"14ccab2072bf4433798a5a8d5576343bafdc3cd1","size":2856,"noattachment":false,"key":"/duck/-/duck-0.1.8.tgz","tarball":"http://registry.cnpm.dingdandao.com/duck/download/duck-0.1.8.tgz"},"maintainers":[{"name":"mwilliamson","email":""}],"directories":{},"publish_time":1345931502758,"_hasShrinkwrap":false,"_cnpm_publish_time":1345931502758,"_cnpmcore_publish_time":"2021-12-16T21:21:48.291Z"}},"readme":"# duck.js -- rich matchers with helpful messages on match failure\n\nduck.js allows you to perform assertions on complex objects.\nWhen those assertions fail, duck.js will try to produce helpful error messages.\nFor instance, suppose you want to assert the same property on an array of objects:\n\n```javascript\nvar duck = require(\"duck\");\nvar isArray = duck.isArray;\nvar hasProperties = duck.hasProperties;\n\nvar users = fetchUsers();\nduck.assertThat(users, isArray([\n    hasProperties({name: \"Bob\"}),\n    hasProperties({name: \"Jim\"}),\n]));\n```\n\nwhich might produce an error message like:\n\n```\nExpected [object with properties {\n    name: 'Bob'\n}, object with properties {\n    name: 'Jim'\n}]\nbut element at index 0 didn't match:\n    value of property \"name\" didn't match:\n        was 'Jim'\n        expected 'Bob'\n    expected object with properties {\n        name: 'Bob'\n    }\nelement at index 1 didn't match:\n    value of property \"name\" didn't match:\n        was 'Bob'\n        expected 'Jim'\n    expected object with properties {\n        name: 'Jim'\n    }\n```\n\n## API\n\nThe below is a quick reference to the API.\nFor more examples, take a look at the tests.\n\n### duck.assertThat(value, matcher)\n\nAssert that `value` satifies `matcher`.\n\nIf `value` satifies `matcher`, return normally, otherwise throw an\nAssertionError describing the mismatch.\n\n### duck.is(value)\n\nIf `value` is a matcher, return that matcher,\notherwise return `duck.equalTo(value)`.\n\n### duck.equalTo(value)\n\nMatcher for deep equality on `value`.\n\n### duck.isObject(matcherObj)\n\nAn object `obj` matches `duck.isObject(matcherObj)` if:\n\n* `obj` matches `duck.hasProperties(matcherObj)`, and\n* there is no key that is present in `obj` but not in `matcherObj`\n\nSample usage:\n\n```javascript\nduck.isObject({\n    name: \"Bob\",\n    address: duck.isObject({\n        city: \"Cambridge\",\n        county: \"UK\"\n    })\n})\n```\n\n`duck.is` is called on each value of the matcher object, meaning that the\nabove is equivalent to:\n\n```javascript\nduck.isObject({\n    name: duck.is(\"Bob\"),\n    address: duck.isObject({\n        city: duck.is(\"Cambridge\"),\n        county: duck.is(\"UK\")\n    })\n})\n```\n\n### duck.hasProperties(matcherProperties)\n\nAn object `obj` matches `duck.hasProperties(matcherProperties)` if,\nfor each `key` in `matcherProperties`, `matcherProperties[key].matches(obj[key])`\n\nSample usage:\n\n```javascript\nduck.hasProperties({\n    name: \"Bob\",\n    address: duck.hasProperties({\n        city: \"Cambridge\",\n        county: \"UK\"\n    })\n})\n```\n\n`duck.is` is called on each value of the matcher object, meaning that the\nabove is equivalent to:\n\n```javascript\nduck.hasProperties({\n    name: duck.is(\"Bob\"),\n    address: duck.hasProperties({\n        city: duck.is(\"Cambridge\"),\n        county: duck.is(\"UK\")\n    })\n})\n```\n\n### duck.isArray(matcherArray)\n\nAn array `blah` matches `duck.isArray(matcherArray)` if:\n\n* `blah.length == matcherArray.length`, and\n* For `0 <= i < array.length`, `matcherArray[i].matches(blah[i])`\n\nSample usage:\n\n```javascript\nduck.isArray([\n    duck.hasProperties({name: \"Bob\"}),\n    duck.hasProperties({name: \"Jim\"}),\n]))\n```\n\n`duck.is` is called on each element of the matcher array, meaning that the\nfollowing are equivalent:\n\n```javascript\nduck.isArray([\"apple\", \"banana\"])\n\nduck.isArray([duck.is(\"apple\"), duck.is(\"banana\")])\n```\n\n### Matcher\n\nEach matcher has the following methods:\n\n#### matcher.matches(value)\n\nReturn `true` if `value` satifies this matcher, false otherwise.\n\n#### matcher.describeMismatch(value)\n\nGenerate a string describing why `value` doesn't satisfy this matcher.\nBehaviour is undefined if `value` actually satisifies the matcher.\n\n#### matcher.matchesWithDescription(value)\n\nEquivalent to:\n\n```javascript\nvar isMatch = this.matches(value);\nreturn {\n    matches: isMatch,\n    description: isMatch ? \"\" : this.describeMismatch(value)\n};\n```\n\nUseful if you're likely to want both the boolean and the mismatch description.\n\n#### matcher.describeSelf()\n\nGenerate a string describing the matcher.\n\n## Thanks\n\nThanks to [Hamcrest](http://hamcrest.org/) for inspiration.\n","_attachments":{},"homepage":"https://github.com/mwilliamson/duck.js#readme","bugs":{"url":"https://github.com/mwilliamson/duck.js/issues"},"license":"BSD"}