From 2080ec274286d2096cf254bd9b097a1f0039bf68 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 19:25:12 +0200 Subject: [PATCH 01/21] Upgrade ESLint to latest version --- package-lock.json | 355 +++++++++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 193 insertions(+), 164 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1ae421519..97d067a89 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,26 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "@babel/code-frame": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0.tgz", + "integrity": "sha512-OfC2uemaknXr87bdLUkWog7nYuliM9Ij5HUcajsVcMCpQrcLmtxRbVFTIqmcSkSeYRBFBRxs2FiUqFJDLdiebA==", + "dev": true, + "requires": { + "@babel/highlight": "^7.0.0" + } + }, + "@babel/highlight": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.0.0.tgz", + "integrity": "sha512-UFMC4ZeFC48Tpvj7C8UgLvtkaUuovQX+5xNWrsIoMG8o2z+XFKjKaN9iVmS84dPwVN00W4wPmqvYoZF3EGAsfw==", + "dev": true, + "requires": { + "chalk": "^2.0.0", + "esutils": "^2.0.2", + "js-tokens": "^4.0.0" + } + }, "@browserify/acorn5-object-spread": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@browserify/acorn5-object-spread/-/acorn5-object-spread-5.0.1.tgz", @@ -137,18 +157,18 @@ } }, "acorn-jsx": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-3.0.1.tgz", - "integrity": "sha1-r9+UiPsezvyDSPb7IvRk4ypYs2s=", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-4.1.1.tgz", + "integrity": "sha512-JY+iV6r+cO21KtntVvFkD+iqjtdpRUpGqKWgfkCdZq1R+kbreEl8EcdcJR4SmiIgsIQT33s6QzheQ9a275Q8xw==", "dev": true, "requires": { - "acorn": "^3.0.4" + "acorn": "^5.0.3" }, "dependencies": { "acorn": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-3.3.0.tgz", - "integrity": "sha1-ReN/s56No/JbruP/U2niu18iAXo=", + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", "dev": true } } @@ -182,21 +202,21 @@ } }, "ajv": { - "version": "5.5.2", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", - "integrity": "sha1-c7Xuyj+rZT49P5Qis0GtQiBdyWU=", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.5.4.tgz", + "integrity": "sha512-4Wyjt8+t6YszqaXnLDfMmG/8AlO5Zbcsy3ATHncCzjW/NoPzAId8AK6749Ybjmdt+kUY1gP60fCu46oDxPv/mg==", "dev": true, "requires": { - "co": "^4.6.0", - "fast-deep-equal": "^1.0.0", + "fast-deep-equal": "^2.0.1", "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.3.0" + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" } }, "ajv-keywords": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-2.1.1.tgz", - "integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.2.0.tgz", + "integrity": "sha1-6GuBnGAs+IIa1jdBNpjx3sAhhHo=", "dev": true }, "align-text": { @@ -394,47 +414,6 @@ "integrity": "sha512-jp/uFnooOiO+L211eZOoSyzpOITMXx1rBITauYykG3BRYPu8h0UcxsPNB04RR5vo4Tyz3+ay17tR6JVf9qzYWg==", "dev": true }, - "babel-code-frame": { - "version": "6.26.0", - "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", - "integrity": "sha1-Y/1D99weO7fONZR9uP42mj9Yx0s=", - "dev": true, - "requires": { - "chalk": "^1.1.3", - "esutils": "^2.0.2", - "js-tokens": "^3.0.2" - }, - "dependencies": { - "chalk": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", - "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", - "dev": true, - "requires": { - "ansi-styles": "^2.2.1", - "escape-string-regexp": "^1.0.2", - "has-ansi": "^2.0.0", - "strip-ansi": "^3.0.0", - "supports-color": "^2.0.0" - } - }, - "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", - "dev": true, - "requires": { - "ansi-regex": "^2.0.0" - } - }, - "supports-color": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", - "dev": true - } - } - }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -905,9 +884,9 @@ } }, "chardet": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz", - "integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I=", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", + "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, "chokidar": { @@ -1055,12 +1034,6 @@ "integrity": "sha1-YT+2hjmyaklKxTJT4Vsaa9iK2oU=", "dev": true }, - "co": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", - "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=", - "dev": true - }, "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", @@ -1645,62 +1618,94 @@ } }, "eslint": { - "version": "4.19.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-4.19.1.tgz", - "integrity": "sha512-bT3/1x1EbZB7phzYu7vCr1v3ONuzDtX8WjuM9c0iYxe+cq+pwcKEoQjl7zd3RpC6YOLgnSy3cTN58M2jcoPDIQ==", + "version": "5.6.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-5.6.1.tgz", + "integrity": "sha512-hgrDtGWz368b7Wqf+v1Z69O3ZebNR0+GA7PtDdbmuz4rInFVUV9uw7whjZEiWyLzCjVb5Rs5WRN1TAS6eo7AYA==", "dev": true, "requires": { - "ajv": "^5.3.0", - "babel-code-frame": "^6.22.0", + "@babel/code-frame": "^7.0.0", + "ajv": "^6.5.3", "chalk": "^2.1.0", - "concat-stream": "^1.6.0", - "cross-spawn": "^5.1.0", - "debug": "^3.1.0", + "cross-spawn": "^6.0.5", + "debug": "^4.0.1", "doctrine": "^2.1.0", - "eslint-scope": "^3.7.1", + "eslint-scope": "^4.0.0", + "eslint-utils": "^1.3.1", "eslint-visitor-keys": "^1.0.0", - "espree": "^3.5.4", - "esquery": "^1.0.0", + "espree": "^4.0.0", + "esquery": "^1.0.1", "esutils": "^2.0.2", "file-entry-cache": "^2.0.0", "functional-red-black-tree": "^1.0.1", "glob": "^7.1.2", - "globals": "^11.0.1", - "ignore": "^3.3.3", + "globals": "^11.7.0", + "ignore": "^4.0.6", "imurmurhash": "^0.1.4", - "inquirer": "^3.0.6", - "is-resolvable": "^1.0.0", - "js-yaml": "^3.9.1", + "inquirer": "^6.1.0", + "is-resolvable": "^1.1.0", + "js-yaml": "^3.12.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.3.0", - "lodash": "^4.17.4", - "minimatch": "^3.0.2", + "lodash": "^4.17.5", + "minimatch": "^3.0.4", "mkdirp": "^0.5.1", "natural-compare": "^1.4.0", "optionator": "^0.8.2", "path-is-inside": "^1.0.2", "pluralize": "^7.0.0", "progress": "^2.0.0", - "regexpp": "^1.0.1", + "regexpp": "^2.0.0", "require-uncached": "^1.0.3", - "semver": "^5.3.0", + "semver": "^5.5.1", "strip-ansi": "^4.0.0", - "strip-json-comments": "~2.0.1", - "table": "4.0.2", - "text-table": "~0.2.0" + "strip-json-comments": "^2.0.1", + "table": "^4.0.3", + "text-table": "^0.2.0" }, "dependencies": { - "concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", "dev": true, "requires": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" } + }, + "debug": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.0.1.tgz", + "integrity": "sha512-K23FHJ/Mt404FSlp6gSZCevIbTMLX0j3fmHhUEhQ3Wq0FMODW3+cUSoLdy1Gx4polAf4t/lphhmHH35BB8cLYw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "js-yaml": { + "version": "3.12.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.0.tgz", + "integrity": "sha512-PIt2cnwmPfL4hKNwqeiuz4bKfnzHTBv6HyVgjahA6mPLwPDzjDWrplJBMjHUFxku/N3FlmrbyPclad+I+4mJ3A==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, + "ms": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", + "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "dev": true + }, + "semver": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz", + "integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==", + "dev": true } } }, @@ -1735,15 +1740,21 @@ } }, "eslint-scope": { - "version": "3.7.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz", - "integrity": "sha1-PWPD7f2gLgbgGkUq2IyqzHzctug=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz", + "integrity": "sha512-1G6UTDi7Jc1ELFwnR58HV4fK9OQK4S6N985f166xqXxpjU6plxFISJa2Ba9KCQuFa8RCnj/lSFJbHo7UFDBnUA==", "dev": true, "requires": { "esrecurse": "^4.1.0", "estraverse": "^4.1.1" } }, + "eslint-utils": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-1.3.1.tgz", + "integrity": "sha512-Z7YjnIldX+2XMcjr7ZkgEsOj/bREONV60qYeB/bjMAqqqZ4zxKyWX+BOUkdmRmA9riiIPVvo5x86m5elviOk0Q==", + "dev": true + }, "eslint-visitor-keys": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", @@ -1757,19 +1768,19 @@ "dev": true }, "espree": { - "version": "3.5.4", - "resolved": "https://registry.npmjs.org/espree/-/espree-3.5.4.tgz", - "integrity": "sha512-yAcIQxtmMiB/jL32dzEp2enBeidsB7xWPLNiw3IIkpVds1P+h7qF9YwJq1yUNzp2OKXgAprs4F61ih66UsoD1A==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-4.0.0.tgz", + "integrity": "sha512-kapdTCt1bjmspxStVKX6huolXVV5ZfyZguY1lcfhVVZstce3bqxH9mcLzNn3/mlgW6wQ732+0fuG9v7h0ZQoKg==", "dev": true, "requires": { - "acorn": "^5.5.0", - "acorn-jsx": "^3.0.0" + "acorn": "^5.6.0", + "acorn-jsx": "^4.1.1" }, "dependencies": { "acorn": { - "version": "5.5.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.5.3.tgz", - "integrity": "sha512-jd5MkIUlbbmb07nXH0DT3y7rDVtkzDi4XZOUVWAer8ajmF/DTSSbl5oNFyDOl/OXA33Bl79+ypHhl2pN20VeOQ==", + "version": "5.7.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", + "integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==", "dev": true } } @@ -1887,13 +1898,13 @@ } }, "external-editor": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", - "integrity": "sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-3.0.3.tgz", + "integrity": "sha512-bn71H9+qWoOQKyZDo25mOMVpSmXROAsTJVVVYzrrtol3d4y+AsKjf4Iwl2Q+IuT0kFSQ1qo166UuIwqYq7mGnA==", "dev": true, "requires": { - "chardet": "^0.4.0", - "iconv-lite": "^0.4.17", + "chardet": "^0.7.0", + "iconv-lite": "^0.4.24", "tmp": "^0.0.33" } }, @@ -1970,9 +1981,9 @@ } }, "fast-deep-equal": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-1.1.0.tgz", - "integrity": "sha1-wFNHeBfIa1HaqFPIHgWbcz0CNhQ=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", "dev": true }, "fast-json-stable-stringify": { @@ -2763,9 +2774,9 @@ } }, "globals": { - "version": "11.5.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-11.5.0.tgz", - "integrity": "sha512-hYyf+kI8dm3nORsiiXUQigOU62hDLfJ9G01uyGMxhc6BKsircrUhC4uJPQPUSuq2GrTmiiEt7ewxlMdBewfmKQ==", + "version": "11.8.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.8.0.tgz", + "integrity": "sha512-io6LkyPVuzCHBSQV9fmOwxZkUk6nIaGmxheLDgmuFv89j0fm2aqDbIXKAGfzCMHqz3HLF2Zf8WSG6VqMh2qFmA==", "dev": true }, "globby": { @@ -2932,9 +2943,9 @@ } }, "iconv-lite": { - "version": "0.4.23", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", - "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" @@ -2953,9 +2964,9 @@ "dev": true }, "ignore": { - "version": "3.3.5", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.5.tgz", - "integrity": "sha512-JLH93mL8amZQhh/p6mfQgVBH3M6epNq3DfsXsTSuSrInVjwyYlFE1nv2AgfRCC8PoOhM0jwQ5v8s9LgbK7yGDw==", + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", "dev": true }, "imurmurhash": { @@ -3011,25 +3022,35 @@ } }, "inquirer": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-3.3.0.tgz", - "integrity": "sha512-h+xtnyk4EwKvFWHrUYsWErEVR+igKtLdchu+o0Z1RL7VU/jVMFbYir2bp6bAj8efFNxWqHX0dIss6fJQ+/+qeQ==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/inquirer/-/inquirer-6.2.0.tgz", + "integrity": "sha512-QIEQG4YyQ2UYZGDC4srMZ7BjHOmNk1lR2JQj5UknBapklm6WHA+VVH7N+sUdX3A7NeCfGF8o4X1S3Ao7nAcIeg==", "dev": true, "requires": { "ansi-escapes": "^3.0.0", "chalk": "^2.0.0", "cli-cursor": "^2.1.0", "cli-width": "^2.0.0", - "external-editor": "^2.0.4", + "external-editor": "^3.0.0", "figures": "^2.0.0", - "lodash": "^4.3.0", + "lodash": "^4.17.10", "mute-stream": "0.0.7", "run-async": "^2.2.0", - "rx-lite": "^4.0.8", - "rx-lite-aggregates": "^4.0.8", + "rxjs": "^6.1.0", "string-width": "^2.1.0", "strip-ansi": "^4.0.0", "through": "^2.3.6" + }, + "dependencies": { + "rxjs": { + "version": "6.3.3", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz", + "integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==", + "dev": true, + "requires": { + "tslib": "^1.9.0" + } + } } }, "insert-module-globals": { @@ -3414,9 +3435,9 @@ "dev": true }, "js-tokens": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", - "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", "dev": true }, "js-yaml": { @@ -3445,9 +3466,9 @@ } }, "json-schema-traverse": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz", - "integrity": "sha1-NJptRMU6Ud6JtAgFxdXlm0F9M0A=", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", "dev": true }, "json-stable-stringify": { @@ -5149,7 +5170,7 @@ "pluralize": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/pluralize/-/pluralize-7.0.0.tgz", - "integrity": "sha1-KYuJ34uTsCIdv0Ia0rGx6iP8Z3c=", + "integrity": "sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==", "dev": true }, "prelude-ls": { @@ -5567,9 +5588,9 @@ } }, "regexpp": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-1.1.0.tgz", - "integrity": "sha512-LOPw8FpgdQF9etWMaAfG/WRthIdXJGYp4mJ2Jgn/2lpkbod9jPn0t9UqN7AxBOKNfzRbYyVfgc7Vk4t/MpnXgw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-2.0.1.tgz", + "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, "remove-trailing-separator": { @@ -5801,21 +5822,6 @@ "is-promise": "^2.1.0" } }, - "rx-lite": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/rx-lite/-/rx-lite-4.0.8.tgz", - "integrity": "sha1-Cx4Rr4vESDbwSmQH6S2kJGe3lEQ=", - "dev": true - }, - "rx-lite-aggregates": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/rx-lite-aggregates/-/rx-lite-aggregates-4.0.8.tgz", - "integrity": "sha1-dTuHqJoRyVRnxKwWJsTvxOBcZ74=", - "dev": true, - "requires": { - "rx-lite": "*" - } - }, "rxjs": { "version": "5.5.11", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.5.11.tgz", @@ -6098,7 +6104,7 @@ "string-width": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha1-q5Pyeo3BPSjKyBXEYhQ6bZASrp4=", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", "dev": true, "requires": { "is-fullwidth-code-point": "^2.0.0", @@ -6217,13 +6223,13 @@ } }, "table": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/table/-/table-4.0.2.tgz", - "integrity": "sha512-UUkEAPdSGxtRpiV9ozJ5cMTtYiqz7Ni1OGqLXRCynrvzdtR1p+cfOWe2RJLwvUG8hNanaSRjecIqwOjqeatDsA==", + "version": "4.0.3", + "resolved": "http://registry.npmjs.org/table/-/table-4.0.3.tgz", + "integrity": "sha512-S7rnFITmBH1EnyKcvxBh1LjYeQMmnZtCXSEbHcH6S0NoKit24ZuFO/T1vDcLdYsLQkM188PVVhQmzKIuThNkKg==", "dev": true, "requires": { - "ajv": "^5.2.3", - "ajv-keywords": "^2.1.0", + "ajv": "^6.0.1", + "ajv-keywords": "^3.0.0", "chalk": "^2.1.0", "lodash": "^4.17.4", "slice-ansi": "1.0.0", @@ -6321,6 +6327,12 @@ } } }, + "tslib": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", + "integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==", + "dev": true + }, "tty-browserify": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", @@ -6390,6 +6402,23 @@ "integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo=", "dev": true }, + "uri-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", + "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", + "dev": true, + "requires": { + "punycode": "^2.1.0" + }, + "dependencies": { + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "dev": true + } + } + }, "url": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz", diff --git a/package.json b/package.json index 4be84e869..fc4fb37dd 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "@sinonjs/referee": "^2.5.2", "browserify": "^15.1.0", "dependency-check": "^2.9.1", - "eslint": "^4.19.1", + "eslint": "^5.6.1", "eslint-config-sinon": "^1.0.0", "eslint-plugin-ie11": "^1.0.0", "eslint-plugin-local-rules": "^0.1.0", From 7b0826b8cd4dfe3fac4688117c6ba4dea55a3d14 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 19:26:00 +0200 Subject: [PATCH 02/21] Remove PhantomJS specfic conditional We're not testing in PhantomJS anymore --- test/util/core/wrap-method-test.js | 61 ++++++++++++++---------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/test/util/core/wrap-method-test.js b/test/util/core/wrap-method-test.js index 07e8913c1..ebf559692 100644 --- a/test/util/core/wrap-method-test.js +++ b/test/util/core/wrap-method-test.js @@ -162,44 +162,39 @@ describe("util/core/wrapMethod", function () { } }); - var overridingErrorAndTypeError = (function () { - return !(typeof navigator === "object" && /PhantomJS/.test(navigator.userAgent)); - }()); - if (overridingErrorAndTypeError) { - describe("originating stack traces", function () { - beforeEach(function () { - this.oldError = Error; - this.oldTypeError = TypeError; - - var i = 0; - - Error = TypeError = function () { // eslint-disable-line no-native-reassign, no-undef - this.stack = ":STACK" + ++i + ":"; - }; - }); + describe("originating stack traces", function () { + beforeEach(function () { + this.oldError = Error; + this.oldTypeError = TypeError; - afterEach(function () { - Error = this.oldError; // eslint-disable-line no-native-reassign, no-undef - TypeError = this.oldTypeError; // eslint-disable-line no-native-reassign, no-undef - }); + var i = 0; - it("throws with stack trace showing original wrapMethod call", function () { - var object = { method: function () {} }; - wrapMethod(object, "method", function () { - return "original"; - }); + Error = TypeError = function () { // eslint-disable-line no-native-reassign, no-undef + this.stack = ":STACK" + ++i + ":"; + }; + }); - assert.exception( - function () { - wrapMethod(object, "method", function () {}); - }, - { - stack: ":STACK2:\n--------------\n:STACK1:" - } - ); + afterEach(function () { + Error = this.oldError; // eslint-disable-line no-native-reassign, no-undef + TypeError = this.oldTypeError; // eslint-disable-line no-native-reassign, no-undef + }); + + it("throws with stack trace showing original wrapMethod call", function () { + var object = { method: function () {} }; + wrapMethod(object, "method", function () { + return "original"; }); + + assert.exception( + function () { + wrapMethod(object, "method", function () {}); + }, + { + stack: ":STACK2:\n--------------\n:STACK1:" + } + ); }); - } + }); if (typeof window !== "undefined") { describe("in browser", function () { From 720743b088cfe9aa91dfe9a7a903c48ed3ff9f0e Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 19:28:50 +0200 Subject: [PATCH 03/21] Replace deprecated no-native-reassign with no-global-assign --- test/util/core/wrap-method-test.js | 9 ++++++--- test/util/fake-timers-test.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/util/core/wrap-method-test.js b/test/util/core/wrap-method-test.js index ebf559692..cccb1f604 100644 --- a/test/util/core/wrap-method-test.js +++ b/test/util/core/wrap-method-test.js @@ -169,14 +169,17 @@ describe("util/core/wrapMethod", function () { var i = 0; - Error = TypeError = function () { // eslint-disable-line no-native-reassign, no-undef + // eslint-disable-next-line no-global-assign + Error = TypeError = function () { this.stack = ":STACK" + ++i + ":"; }; }); afterEach(function () { - Error = this.oldError; // eslint-disable-line no-native-reassign, no-undef - TypeError = this.oldTypeError; // eslint-disable-line no-native-reassign, no-undef + // eslint-disable-next-line no-global-assign + Error = this.oldError; + // eslint-disable-next-line no-global-assign + TypeError = this.oldTypeError; }); it("throws with stack trace showing original wrapMethod call", function () { diff --git a/test/util/fake-timers-test.js b/test/util/fake-timers-test.js index fffe46047..be7151cda 100644 --- a/test/util/fake-timers-test.js +++ b/test/util/fake-timers-test.js @@ -638,7 +638,8 @@ describe("fakeTimers.clock", function () { it("creates real Date objects when Date constructor is gone", function () { var realDate = new Date(); - Date = function () {}; // eslint-disable-line no-undef, no-native-reassign + // eslint-disable-next-line no-global-assign + Date = function () {}; this.global.Date = function () {}; var date = new this.clock.Date(); From 5715752d6ebcd691037f26f87f5442ba1c61394b Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 19:33:54 +0200 Subject: [PATCH 04/21] Fix lint violations for getter-return --- test/sandbox-test.js | 4 +++- test/stub-test.js | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 4da6068dd..b5c4399d8 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -971,7 +971,9 @@ describe("Sandbox", function () { it("should error when descriptor has no setter", function () { var sandbox = this.sandbox; var object = { - get catpants() {} + get catpants() { + return; + } }; assert.exception( diff --git a/test/stub-test.js b/test/stub-test.js index d6250fc9d..0fcea0333 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -1295,6 +1295,7 @@ describe("stub", function () { var obj = { get prop() { fail("should not call getter"); + return; } }; @@ -2910,6 +2911,7 @@ describe("stub", function () { var myObj = { get prop() { fail("should not call the old getter"); + return; } }; From 8192c78aeff65568470ac496f92d38d85d697285 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 19:50:56 +0200 Subject: [PATCH 05/21] Fix lint violations for valid-jsdoc --- lib/sinon/util/core/is-es-module.js | 4 ++++ lib/sinon/util/fake_timers.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/sinon/util/core/is-es-module.js b/lib/sinon/util/core/is-es-module.js index c1ab20e9d..157b9f79c 100644 --- a/lib/sinon/util/core/is-es-module.js +++ b/lib/sinon/util/core/is-es-module.js @@ -6,6 +6,10 @@ * As the exports from a module is immutable we cannot alter the exports * using spies or stubs. Let the consumer know this to avoid bug reports * on weird error messages. + * + * @param {Object} object The object to examine + * + * @returns {Boolean} true when the object is a module */ module.exports = function (object) { return ( diff --git a/lib/sinon/util/fake_timers.js b/lib/sinon/util/fake_timers.js index 6d6e66db3..7be8e273f 100644 --- a/lib/sinon/util/fake_timers.js +++ b/lib/sinon/util/fake_timers.js @@ -4,7 +4,8 @@ var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnPropert var llx = require("lolex"); /** - * @param config {number|Date|Object} the unix epoch value to install with (default 0) or + * @param {number|Date|Object} args The unix epoch value to install with (default 0) + * @returns {Object} Returns a lolex clock instance */ exports.useFakeTimers = function (args) { var config = {}; From 9e3db953e163cd336ab25a208779767298f539c7 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 19:58:20 +0200 Subject: [PATCH 06/21] Fix lint violations for block-scoped-var --- lib/sinon/util/core/wrap-method.js | 4 ++-- test/issues/issues-test.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/sinon/util/core/wrap-method.js b/lib/sinon/util/core/wrap-method.js index 975842ecc..811b95444 100644 --- a/lib/sinon/util/core/wrap-method.js +++ b/lib/sinon/util/core/wrap-method.js @@ -49,7 +49,7 @@ module.exports = function wrapMethod(object, property, method) { } } - var error, wrappedMethod, i; + var error, wrappedMethod, i, wrappedMethodDesc; function simplePropertyAssignment() { wrappedMethod = object[property]; @@ -64,7 +64,7 @@ module.exports = function wrapMethod(object, property, method) { if (hasES5Support) { var methodDesc = (typeof method === "function") ? {value: method} : method; - var wrappedMethodDesc = getPropertyDescriptor(object, property); + wrappedMethodDesc = getPropertyDescriptor(object, property); if (!wrappedMethodDesc) { error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index 0997ae431..3b5854510 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -138,8 +138,10 @@ describe("issues", function () { } } + var oldWatch; + try { // eslint-disable-line no-restricted-syntax - var oldWatch = Object.prototype.watch; + oldWatch = Object.prototype.watch; if (typeof Object.prototype.watch !== "function") { Object.prototype.watch = function rolex() {}; // eslint-disable-line no-extend-native From e0b7240c2e6930fc2aecef4cf816368600827815 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 20:24:37 +0200 Subject: [PATCH 07/21] Fix lint violtions for no-empty-function --- lib/sinon/assert.js | 4 +- lib/sinon/spy.js | 8 ++- test/assert-test.js | 34 +++++------ test/call-test.js | 30 ++++----- test/fake-test.js | 16 ++--- test/issues/issues-test.js | 22 +++---- test/match-test.js | 24 ++++---- test/mock-test.js | 18 +++--- test/sandbox-test.js | 74 +++++++++++------------ test/spy-test.js | 50 +++++++-------- test/stub-test.js | 74 +++++++++++------------ test/util/core/called-in-order-test.js | 6 +- test/util/core/deep-equal-test.js | 4 +- test/util/core/function-to-string-test.js | 2 +- test/util/core/get-next-tick-test.js | 4 +- test/util/core/restore-test.js | 12 ++-- test/util/core/typeOf-test.js | 2 +- test/util/core/walk-test.js | 6 +- test/util/core/wrap-method-test.js | 68 ++++++++++----------- test/util/fake-timers-test.js | 16 ++--- 20 files changed, 241 insertions(+), 233 deletions(-) diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 5b7e02a7b..f7e0e35c1 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -107,7 +107,9 @@ assert = { throw error; }, - pass: function pass() {}, + pass: function pass() { + return; + }, callOrder: function assertCallOrder() { verifyIsStub.apply(null, arguments); diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 2392f51db..de65b1b7d 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -38,7 +38,9 @@ function spy(object, property, types) { } if (!object && !property) { - return spy.create(function () {}); + return spy.create(function () { + return; + }); } if (!types) { @@ -150,7 +152,9 @@ var spyApi = { var name; if (typeof func !== "function") { - func = function () { }; + func = function () { + return; + }; } else { name = functionName(func); } diff --git a/test/assert-test.js b/test/assert-test.js index 5a3dae6d1..38dc0ff1b 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -38,8 +38,8 @@ describe("assert", function () { }); it("supports proxy property", function () { - var api = { method: function () {} }; - api.method.proxy = function () {}; + var api = { method: function () { return; } }; + api.method.proxy = function () { return; }; sinonSpy(api, "method"); api.method(); @@ -114,7 +114,7 @@ describe("assert", function () { it("fails when method is not stub", function () { assert.exception(function () { - sinonAssert.called(function () {}); + sinonAssert.called(function () { return; }); }); assert(sinonAssert.fail.called); @@ -176,7 +176,7 @@ describe("assert", function () { it("fails when method is not stub", function () { assert.exception(function () { - sinonAssert.notCalled(function () {}); + sinonAssert.notCalled(function () { return; }); }); assert(sinonAssert.fail.called); @@ -234,7 +234,7 @@ describe("assert", function () { it("fails when method is not stub", function () { assert.exception(function () { - sinonAssert.calledOnce(function () {}); + sinonAssert.calledOnce(function () { return; }); }); assert(sinonAssert.fail.called); @@ -502,7 +502,7 @@ describe("assert", function () { sinonStub(this.stub, "calledOn"); assert.exception(function () { - sinonAssert.calledOn(function () {}, object); + sinonAssert.calledOn(function () { return; }, object); }); assert.isFalse(this.stub.calledOn.calledWith(object)); @@ -583,7 +583,7 @@ describe("assert", function () { sinonStub(this.stub, "calledWithNew"); assert.exception(function () { - sinonAssert.calledWithNew(function () {}); + sinonAssert.calledWithNew(function () { return; }); }); assert.isFalse(this.stub.calledWithNew.called); @@ -659,7 +659,7 @@ describe("assert", function () { sinonStub(this.stub, "alwaysCalledWithNew"); assert.exception(function () { - sinonAssert.alwaysCalledWithNew(function () {}); + sinonAssert.alwaysCalledWithNew(function () { return; }); }); assert.isFalse(this.stub.alwaysCalledWithNew.called); @@ -952,7 +952,7 @@ describe("assert", function () { it("fails if method is not fake", function () { assert.exception(function () { - sinonAssert.alwaysCalledOn(function () {}, {}); + sinonAssert.alwaysCalledOn(function () { return; }, {}); }); }); @@ -1005,7 +1005,7 @@ describe("assert", function () { it("fails if method is not fake", function () { assert.exception(function () { - sinonAssert.alwaysCalledWith(function () {}); + sinonAssert.alwaysCalledWith(function () { return; }); }); }); @@ -1163,7 +1163,7 @@ describe("assert", function () { describe("message", function () { beforeEach(function () { this.obj = { - doSomething: function () {} + doSomething: function () { return; } }; sinonSpy(this.obj, "doSomething"); @@ -1217,7 +1217,7 @@ describe("assert", function () { }); it("assert.callOrder exception message", function () { - var obj = { doop: function () {}, foo: function () {} }; + var obj = { doop: function () { return; }, foo: function () { return; } }; sinonSpy(obj, "doop"); sinonSpy(obj, "foo"); @@ -1233,7 +1233,7 @@ describe("assert", function () { }); it("assert.callOrder with missing first call exception message", function () { - var obj = { doop: function () {}, foo: function () {} }; + var obj = { doop: function () { return; }, foo: function () { return; } }; sinonSpy(obj, "doop"); sinonSpy(obj, "foo"); @@ -1247,7 +1247,7 @@ describe("assert", function () { }); it("assert.callOrder with missing last call exception message", function () { - var obj = { doop: function () {}, foo: function () {} }; + var obj = { doop: function () { return; }, foo: function () { return; } }; sinonSpy(obj, "doop"); sinonSpy(obj, "foo"); @@ -1505,7 +1505,7 @@ describe("assert", function () { it("assert.calledWith match.instanceOf exception message", function () { this.obj.doSomething(); - var matcher = sinonMatch.instanceOf(function CustomType() {}); + var matcher = sinonMatch.instanceOf(function CustomType() { return; }); assert.equals( this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), @@ -1553,7 +1553,7 @@ describe("assert", function () { it("assert.calledWith match test function exception message", function () { this.obj.doSomething(); - var matcher = sinonMatch({ test: function custom() {} }); + var matcher = sinonMatch({ test: function custom() { return; } }); assert.equals( this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), @@ -1673,7 +1673,7 @@ describe("assert", function () { var obj = {}; function setupSymbol(symbol) { - obj[symbol] = function () {}; + obj[symbol] = function () { return; }; sinonSpy(obj, symbol); } diff --git a/test/call-test.js b/test/call-test.js index 29c5990ea..cd6a32bab 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -11,8 +11,8 @@ var refute = referee.refute; function spyCallSetUp() { this.thisValue = {}; this.args = [{}, [], new Error(), 3]; - this.returnValue = function () {}; - this.call = sinonSpyCall(function () {}, this.thisValue, + this.returnValue = function () { return; }; + this.call = sinonSpyCall(function () { return; }, this.thisValue, this.args, this.returnValue, null, 0); } @@ -121,14 +121,14 @@ describe("sinonSpy.call", function () { }); it("stores given call id", function () { - var call = sinonSpyCall(function () {}, {}, [], null, null, 42); + var call = sinonSpyCall(function () { return; }, {}, [], null, null, 42); assert.same(call.callId, 42); }); it("throws if callId is undefined", function () { assert.exception(function () { - sinonSpyCall.create(function () {}, {}, []); + sinonSpyCall.create(function () { return; }, {}, []); }); }); @@ -219,13 +219,13 @@ describe("sinonSpy.call", function () { }); it("returns true for no arguments", function () { - var call = sinonSpyCall(function () {}, {}, [], null, null, 0); + var call = sinonSpyCall(function () { return; }, {}, [], null, null, 0); assert(call.calledWithExactly()); }); it("returns false when called with no args but matching one", function () { - var call = sinonSpyCall(function () {}, {}, [], null, null, 0); + var call = sinonSpyCall(function () { return; }, {}, [], null, null, 0); assert.isFalse(call.calledWithExactly({})); }); @@ -463,8 +463,8 @@ describe("sinonSpy.call", function () { describe(".callback", function () { it("it should be a reference for the callback", function () { var spy = sinonSpy(); - var callback1 = function () {}; - var callback2 = function () {}; + var callback1 = function () { return; }; + var callback2 = function () { return; }; spy(1, 2, 3, callback1); assert.equals(spy.getCall(0).callback, callback1); @@ -594,7 +594,7 @@ describe("sinonSpy.call", function () { describe("call.invokeCallback", function () { it("is alias for yield", function () { - var call = sinonSpyCall(function () {}, {}, [], null, null, 0); + var call = sinonSpyCall(function () { return; }, {}, [], null, null, 0); assert.same(call.yield, call.invokeCallback); }); @@ -1040,7 +1040,7 @@ describe("sinonSpy.call", function () { describe("constructor", function () { beforeEach(function () { - this.CustomConstructor = function () {}; + this.CustomConstructor = function () { return; }; this.customPrototype = this.CustomConstructor.prototype; sinonSpy(this, "CustomConstructor"); }); @@ -1082,7 +1082,7 @@ describe("sinonSpy.call", function () { }); it("haves toString method", function () { - var obj = { meth: function () {} }; + var obj = { meth: function () { return; } }; sinonSpy(obj, "meth"); assert.equals(obj.meth.toString(), "meth"); @@ -1095,14 +1095,14 @@ describe("sinonSpy.call", function () { }); it("toString should report name of spied function", function () { - function myTestFunc() {} + function myTestFunc() { return; } var spy = sinonSpy(myTestFunc); assert.equals(spy.toString(), "myTestFunc"); }); it("toString should prefer displayName property if available", function () { - function myTestFunc() {} + function myTestFunc() { return; } myTestFunc.displayName = "My custom method"; var spy = sinonSpy(myTestFunc); @@ -1389,11 +1389,11 @@ describe("sinonSpy.call", function () { describe(".printf", function () { describe("name", function () { it("named", function () { - var named = sinonSpy(function cool() { }); + var named = sinonSpy(function cool() { return; }); assert.equals(named.printf("%n"), "cool"); }); it("anon", function () { - var anon = sinonSpy(function () {}); + var anon = sinonSpy(function () { return; }); assert.equals(anon.printf("%n"), "spy"); var noFn = sinonSpy(); diff --git a/test/fake-test.js b/test/fake-test.js index 850ef48c1..f0cc2d2c2 100644 --- a/test/fake-test.js +++ b/test/fake-test.js @@ -29,7 +29,7 @@ function verifyProxy(func, argument) { }); } -function noop() {} +function noop() { return; } function requirePromiseSupport() { if (typeof Promise !== "function") { @@ -50,7 +50,7 @@ describe("fake", function () { }); describe("when passed a Function", function () { - verifyProxy(fake, function () {}); + verifyProxy(fake, function () { return; }); it("should keep the `this` context of the wrapped function", function () { function method() { return this.foo; } @@ -81,8 +81,8 @@ describe("fake", function () { describe(".callback", function () { it("it should be a reference for the callback in the last call", function () { var f = fake(); - var callback1 = function () {}; - var callback2 = function () {}; + var callback1 = function () { return; }; + var callback2 = function () { return; }; f(1, 2, 3, callback1); assert.equals(f.callback, callback1); @@ -264,7 +264,7 @@ describe("fake", function () { var callback = sinon.spy(); var myFake = fake.yields(); - myFake(function () {}, callback); + myFake(function () { return; }, callback); sinon.assert.calledOnce(callback); }); @@ -273,7 +273,7 @@ describe("fake", function () { var myFake = fake.yields(); assert.exception(function () { - myFake(function () {}, "not a function"); + myFake(function () { return; }, "not a function"); }, /TypeError: Expected last argument to be a function/); }); }); @@ -301,7 +301,7 @@ describe("fake", function () { var callback = sinon.spy(); var myFake = fake.yieldsAsync(); - myFake(function () {}, callback); + myFake(function () { return; }, callback); sinon.assert.notCalled(callback); @@ -316,7 +316,7 @@ describe("fake", function () { var myFake = fake.yieldsAsync(); assert.exception(function () { - myFake(function () {}, "not a function"); + myFake(function () { return; }, "not a function"); }, /TypeError: Expected last argument to be a function/); }); }); diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index 3b5854510..d0b755320 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -75,8 +75,8 @@ describe("issues", function () { describe("#852 - createStubInstance on intherited constructors", function () { it("must not throw error", function () { - var A = function () {}; - var B = function () {}; + var A = function () { return; }; + var B = function () { return; }; B.prototype = Object.create(A.prototype); B.prototype.constructor = A; @@ -89,7 +89,7 @@ describe("issues", function () { describe("#852(2) - createStubInstance should on same constructor", function () { it("must be idempotent", function () { - var A = function () {}; + var A = function () { return; }; refute.exception(function () { sinon.createStubInstance(A); sinon.createStubInstance(A); @@ -98,7 +98,7 @@ describe("issues", function () { }); describe("#950 - first execution of a spy as a method renames that spy", function () { - function bob() {} + function bob() { return; } // IE 11 does not support the function name property if (bob.name) { @@ -144,11 +144,11 @@ describe("issues", function () { oldWatch = Object.prototype.watch; if (typeof Object.prototype.watch !== "function") { - Object.prototype.watch = function rolex() {}; // eslint-disable-line no-extend-native + Object.prototype.watch = function rolex() { return; }; // eslint-disable-line no-extend-native } var stubbedObject = sinon.stub({ - watch: function () {} + watch: function () { return; } }); stubbedObject.watch(); @@ -337,7 +337,7 @@ describe("issues", function () { }); it("can stub methods on the prototype", function () { - var proto = { someFunction: function () {} }; + var proto = { someFunction: function () { return; } }; var instance = Object.create(proto); var stub = sandbox.stub(instance, "someFunction"); @@ -383,7 +383,7 @@ describe("issues", function () { describe("#1442 - callThrough with a mock expectation", function () { it("should call original method", function () { var foo = { - bar: function () { } + bar: function () { return; } }; var mock = this.sandbox.mock(foo); @@ -398,7 +398,7 @@ describe("issues", function () { describe("#1648 - resetHistory ", function () { it("should reset property spies", function () { var obj = { - func: function () {}, + func: function () { return; }, get prop() { return 1; } @@ -538,8 +538,8 @@ describe("issues", function () { describe("#1882", function () { it("should use constructor name when checking deepEquality", function () { - function ClassWithoutProps() {} - function AnotherClassWithoutProps() {} + function ClassWithoutProps() { return; } + function AnotherClassWithoutProps() { return; } ClassWithoutProps.prototype.constructor = ClassWithoutProps; AnotherClassWithoutProps.prototype.constructor = AnotherClassWithoutProps; var arg1 = new ClassWithoutProps(); //arg1.constructor.name === ClassWithoutProps diff --git a/test/match-test.js b/test/match-test.js index 8488833f0..295b613a2 100644 --- a/test/match-test.js +++ b/test/match-test.js @@ -69,7 +69,7 @@ function propertyMatcherTests(matcher, additionalTests) { it("compares with matcher", function () { var has = matcher("callback", sinonMatch.typeOf("function")); - assert(has.test({ callback: function () {} })); + assert(has.test({ callback: function () { return; } })); }); if (typeof additionalTests === "function") { @@ -80,13 +80,13 @@ function propertyMatcherTests(matcher, additionalTests) { describe("sinonMatch", function () { it("returns matcher", function () { - var match = sinonMatch(function () {}); + var match = sinonMatch(function () { return; }); assert(sinonMatch.isMatcher(match)); }); it("exposes test function", function () { - var test = function () {}; + var test = function () { return; }; var match = sinonMatch(test); @@ -300,7 +300,7 @@ describe("sinonMatch", function () { }); it("returns false if test function in object returns nothing", function () { - var match = sinonMatch({ test: function () {}}); + var match = sinonMatch({ test: function () { return; }}); assert.isFalse(match.test()); }); @@ -323,13 +323,13 @@ describe("sinonMatch", function () { it("returns message", function () { var message = "hello sinonMatch"; - var match = sinonMatch(function () {}, message); + var match = sinonMatch(function () { return; }, message); assert.same(match.toString(), message); }); it("defaults to match(functionName)", function () { - var match = sinonMatch(function custom() {}); + var match = sinonMatch(function custom() { return; }); assert.same(match.toString(), "match(custom)"); }); @@ -368,7 +368,7 @@ describe("sinonMatch", function () { it("returns true if test is called with any object", function () { assert(sinonMatch.defined.test({})); - assert(sinonMatch.defined.test(function () {})); + assert(sinonMatch.defined.test(function () { return; })); }); }); @@ -459,7 +459,7 @@ describe("sinonMatch", function () { [1, 2, 3], ["a", "b", "c"], [{ a: "a" }, { b: "b"}], - [function () {}, function () {}], + [function () { return; }, function () { return; }], [null, undefined] ]; @@ -542,13 +542,13 @@ describe("sinonMatch", function () { if (typeof Symbol !== "undefined" && typeof Symbol.hasInstance !== "undefined") { it("does not throw if given argument defines Symbol.hasInstance", function () { var objectWithCustomTypeChecks = {}; - objectWithCustomTypeChecks[Symbol.hasInstance] = function () {}; + objectWithCustomTypeChecks[Symbol.hasInstance] = function () { return; }; sinonMatch.instanceOf(objectWithCustomTypeChecks); }); } it("returns matcher", function () { - var instanceOf = sinonMatch.instanceOf(function () {}); + var instanceOf = sinonMatch.instanceOf(function () { return; }); assert(sinonMatch.isMatcher(instanceOf)); }); @@ -688,7 +688,7 @@ describe("sinonMatch", function () { refute(every.test(1)); refute(every.test("a")); refute(every.test(null)); - refute(every.test(function () {})); + refute(every.test(function () { return; })); }); it("matches an object if the predicate is true for every property", function () { @@ -767,7 +767,7 @@ describe("sinonMatch", function () { refute(some.test(1)); refute(some.test("a")); refute(some.test(null)); - refute(some.test(function () {})); + refute(some.test(function () { return; })); }); it("matches an object if the predicate is true for some of the properties", function () { diff --git a/test/mock-test.js b/test/mock-test.js index 7d93ecabf..8eeb55a3f 100644 --- a/test/mock-test.js +++ b/test/mock-test.js @@ -36,7 +36,7 @@ describe("sinonMock", function () { describe(".expects", function () { beforeEach(function () { - this.mock = sinonMock.create({ someMethod: function () {} }); + this.mock = sinonMock.create({ someMethod: function () { return; } }); }); it("throws without method", function () { @@ -324,7 +324,7 @@ describe("sinonMock", function () { }); it("should not throw when exceeding at least expectation", function () { - var obj = { foobar: function () {} }; + var obj = { foobar: function () { return; } }; var mock = sinonMock(obj); mock.expects("foobar").atLeast(1); @@ -337,7 +337,7 @@ describe("sinonMock", function () { }); it("should not throw when exceeding at least expectation and withargs", function () { - var obj = { foobar: function () {} }; + var obj = { foobar: function () { return; } }; var mock = sinonMock(obj); mock.expects("foobar").withArgs("arg1"); @@ -558,7 +558,7 @@ describe("sinonMock", function () { it("works with sinon matchers", function () { this.expectation.withArgs(sinonMatch.number, sinonMatch.string, sinonMatch.func); - this.expectation(1, "test", function () {}); + this.expectation(1, "test", function () { return; }); assert(this.expectation.met()); }); @@ -710,7 +710,7 @@ describe("sinonMock", function () { describe(".verify", function () { beforeEach(function () { - this.method = function () {}; + this.method = function () { return; }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); }); @@ -947,7 +947,7 @@ describe("sinonMock", function () { describe(".usingPromise", function () { beforeEach(function () { - this.method = function () {}; + this.method = function () { return; }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); }); @@ -986,7 +986,7 @@ describe("sinonMock", function () { describe("mock object", function () { beforeEach(function () { - this.method = function () {}; + this.method = function () { return; }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); }); @@ -1042,7 +1042,7 @@ describe("sinonMock", function () { describe("mock method multiple times", function () { beforeEach(function () { this.thisValue = {}; - this.method = function () {}; + this.method = function () { return; }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); this.mock.expects("method"); @@ -1077,7 +1077,7 @@ describe("sinonMock", function () { }); it("allows mock calls in any order", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; var mock = sinonMock(object); mock.expects("method").once().withArgs(42); mock.expects("method").twice().withArgs("Yeah"); diff --git a/test/sandbox-test.js b/test/sandbox-test.js index b5c4399d8..3ba146880 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -36,7 +36,7 @@ referee.add("fakeServerWithClock", { }); describe("Sandbox", function () { - function noop() {} + function noop() { return; } it("exposes match", function () { var sandbox = new Sandbox(); @@ -71,7 +71,7 @@ describe("Sandbox", function () { }); it("returns a mock", function () { - var object = { method: function () { }}; + var object = { method: function () { return; }}; var actual = this.sandbox.mock(object); actual.expects("method"); @@ -82,7 +82,7 @@ describe("Sandbox", function () { it("adds mock to fake array", function () { var fakes = this.sandbox.getFakes(); - var object = { method: function () { }}; + var object = { method: function () { return; }}; var expected = this.sandbox.mock(object); assert(fakes.indexOf(expected) !== -1); @@ -106,8 +106,8 @@ describe("Sandbox", function () { it("appends mocks and stubs to fake array", function () { var fakes = this.sandbox.getFakes(); - this.sandbox.mock({ method: function () {} }, "method"); - this.sandbox.stub({ method: function () {} }, "method"); + this.sandbox.mock({ method: function () { return; } }, "method"); + this.sandbox.stub({ method: function () { return; } }, "method"); assert.equals(fakes.length, 2); }); @@ -139,8 +139,8 @@ describe("Sandbox", function () { }); it("stubs existing methods", function () { - var Class = function () {}; - Class.prototype.method = function () {}; + var Class = function () { return; }; + Class.prototype.method = function () { return; }; var stub = this.sandbox.createStubInstance(Class); stub.method.returns(3); @@ -162,10 +162,10 @@ describe("Sandbox", function () { }); it("resets all stub methods on reset()", function () { - var Class = function () {}; - Class.prototype.method1 = function () {}; - Class.prototype.method2 = function () {}; - Class.prototype.method3 = function () {}; + var Class = function () { return; }; + Class.prototype.method1 = function () { return; }; + Class.prototype.method2 = function () { return; }; + Class.prototype.method3 = function () { return; }; var stub = this.sandbox.createStubInstance(Class); stub.method1.returns(1); @@ -181,7 +181,7 @@ describe("Sandbox", function () { }); it("doesn't stub fake methods", function () { - var Class = function () {}; + var Class = function () { return; }; var stub = this.sandbox.createStubInstance(Class); assert.exception(function () { @@ -194,7 +194,7 @@ describe("Sandbox", function () { var c = a + b; throw c; }; - Class.prototype.method = function () {}; + Class.prototype.method = function () { return; }; var stub = this.sandbox.createStubInstance(Class); refute.exception(function () { @@ -204,7 +204,7 @@ describe("Sandbox", function () { it("retains non function values", function () { var TYPE = "some-value"; - var Class = function () {}; + var Class = function () { return; }; Class.prototype.type = TYPE; var stub = this.sandbox.createStubInstance(Class); @@ -217,7 +217,7 @@ describe("Sandbox", function () { throw "error"; } }; - var Class = function () {}; + var Class = function () { return; }; Class.prototype = proto; var stub = this.sandbox.createStubInstance(Class); @@ -272,7 +272,7 @@ describe("Sandbox", function () { }); it("creates a stub", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; this.sandbox.stub(object, "method"); @@ -281,7 +281,7 @@ describe("Sandbox", function () { it("adds stub to fake array", function () { var fakes = this.sandbox.getFakes(); - var object = { method: function () {} }; + var object = { method: function () { return; } }; var stub = this.sandbox.stub(object, "method"); assert.isTrue(fakes.indexOf(stub) !== -1); @@ -290,8 +290,8 @@ describe("Sandbox", function () { it("appends stubs to fake array", function () { var fakes = this.sandbox.getFakes(); - this.sandbox.stub({ method: function () {} }, "method"); - this.sandbox.stub({ method: function () {} }, "method"); + this.sandbox.stub({ method: function () { return; } }, "method"); + this.sandbox.stub({ method: function () { return; } }, "method"); assert.equals(fakes.length, 2); }); @@ -299,9 +299,9 @@ describe("Sandbox", function () { it("adds all object methods to fake array", function () { var fakes = this.sandbox.getFakes(); var object = { - method: function () {}, - method2: function () {}, - method3: function () {} + method: function () { return; }, + method2: function () { return; }, + method3: function () { return; } }; Object.defineProperty(object, "method3", { @@ -317,12 +317,12 @@ describe("Sandbox", function () { }); it("returns a stubbed object", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; assert.equals(this.sandbox.stub(object), object); }); it("returns a stubbed method", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; assert.equals(this.sandbox.stub(object, "method"), object.method); }); @@ -334,7 +334,7 @@ describe("Sandbox", function () { it("stubs environment property", function () { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () {}; + deprecated.printWarning = function () { return; }; this.sandbox.stub(process.env, "HELL").value("froze over"); assert.equals(process.env.HELL, "froze over"); @@ -353,7 +353,7 @@ describe("Sandbox", function () { it("stubs number property", function () { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () {}; + deprecated.printWarning = function () { return; }; this.sandbox.stub(this.object, "property").value(1); @@ -364,7 +364,7 @@ describe("Sandbox", function () { it("restores number property", function () { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () {}; + deprecated.printWarning = function () { return; }; this.sandbox.stub(this.object, "property").value(1); this.sandbox.restore(); @@ -376,7 +376,7 @@ describe("Sandbox", function () { it("fails if property does not exist", function () { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () {}; + deprecated.printWarning = function () { return; }; var sandbox = this.sandbox; var object = {}; @@ -394,7 +394,7 @@ describe("Sandbox", function () { var object = {}; var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () {}; + deprecated.printWarning = function () { return; }; assert.exception(function () { sandbox.stub(object, Symbol()); @@ -589,8 +589,8 @@ describe("Sandbox", function () { }); it("should replace a function property", function () { - var replacement = function replacement() {}; - var existing = function existing() {}; + var replacement = function replacement() { return; }; + var existing = function existing() { return; }; var object = { property: existing }; @@ -833,7 +833,7 @@ describe("Sandbox", function () { it("should error when descriptor has no getter", function () { var sandbox = this.sandbox; var object = { // eslint-disable-line accessor-pairs - set catpants(_) {} + set catpants(_) { return; } }; assert.exception( @@ -1028,7 +1028,7 @@ describe("Sandbox", function () { var sandbox = this.sandbox; // eslint-disable-next-line accessor-pairs var object = { - set foo(value) {} + set foo(value) { return; } }; sandbox.replaceSetter(object, "foo", sinonFake()); @@ -1309,7 +1309,7 @@ describe("Sandbox", function () { }); it("calls sinon.useFakeXMLHttpRequest", function () { - var stubXhr = { restore: function () {} }; + var stubXhr = { restore: function () { return; } }; this.sandbox.stub(fakeXhr, "useFakeXMLHttpRequest").returns(stubXhr); var returnedXhr = this.sandbox.useFakeXMLHttpRequest(); @@ -1319,14 +1319,14 @@ describe("Sandbox", function () { }); it("returns fake xhr object created by nise", function () { - this.sandbox.stub(fakeXhr, "useFakeXMLHttpRequest").returns({ restore: function () {} }); + this.sandbox.stub(fakeXhr, "useFakeXMLHttpRequest").returns({ restore: function () { return; } }); this.sandbox.useFakeXMLHttpRequest(); assert(fakeXhr.useFakeXMLHttpRequest.called); }); it("doesn't secretly use useFakeServer", function () { - this.sandbox.stub(fakeServer, "create").returns({ restore: function () {} }); + this.sandbox.stub(fakeServer, "create").returns({ restore: function () { return; } }); this.sandbox.useFakeXMLHttpRequest(); assert(fakeServer.create.notCalled); @@ -1561,7 +1561,7 @@ describe("Sandbox", function () { }); it("does not inject properties if they are already present", function () { - var server = function () {}; + var server = function () { return; }; var clock = {}; var spy = false; var object = { server: server, clock: clock, spy: spy}; diff --git a/test/spy-test.js b/test/spy-test.js index b94d76158..e6ff962ea 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -223,7 +223,7 @@ describe("spy", function () { }); it("returns spy function", function () { - var func = function () {}; + var func = function () { return; }; var spy = createSpy.create(func); assert.isFunction(spy); @@ -231,7 +231,7 @@ describe("spy", function () { }); it("mirrors custom properties on function", function () { - var func = function () {}; + var func = function () { return; }; func.myProp = 42; var spy = createSpy.create(func); @@ -245,7 +245,7 @@ describe("spy", function () { }); it("does not overwrite original create property", function () { - var func = function () {}; + var func = function () { return; }; var object = func.create = {}; var spy = createSpy.create(func); @@ -380,8 +380,8 @@ describe("spy", function () { } var object = { - f1: function () {}, - f2: function () {} + f1: function () { return; }, + f2: function () { return; } }; // f1: the order of withArgs(1), withArgs(1, 1) @@ -440,7 +440,7 @@ describe("spy", function () { }); it("passes 'new' to underlying function", function () { - function TestClass() {} + function TestClass() { return; } var SpyClass = createSpy.create(TestClass); @@ -500,37 +500,39 @@ describe("spy", function () { }); it("retains function length 0", function () { - var spy = createSpy.create(function () {}); + var spy = createSpy.create(function () { return; }); assert.equals(spy.length, 0); }); it("retains function length 1", function () { - var spy = createSpy.create(function (a) {}); // eslint-disable-line no-unused-vars + var spy = createSpy.create(function (a) { return; }); // eslint-disable-line no-unused-vars assert.equals(spy.length, 1); }); it("retains function length 2", function () { - var spy = createSpy.create(function (a, b) {}); // eslint-disable-line no-unused-vars + var spy = createSpy.create(function (a, b) { return; }); // eslint-disable-line no-unused-vars assert.equals(spy.length, 2); }); it("retains function length 3", function () { - var spy = createSpy.create(function (a, b, c) {}); // eslint-disable-line no-unused-vars + var spy = createSpy.create(function (a, b, c) { return; }); // eslint-disable-line no-unused-vars assert.equals(spy.length, 3); }); it("retains function length 4", function () { - var spy = createSpy.create(function (a, b, c, d) {}); // eslint-disable-line no-unused-vars + var spy = createSpy.create(function (a, b, c, d) { return; }); // eslint-disable-line no-unused-vars assert.equals(spy.length, 4); }); it("retains function length 12", function () { - var func12Args = function (a, b, c, d, e, f, g, h, i, j, k, l) {}; // eslint-disable-line no-unused-vars + var func12Args = function (a, b, c, d, e, f, g, h, i, j, k, l) { // eslint-disable-line no-unused-vars + return; + }; var spy = createSpy.create(func12Args); assert.equals(spy.length, 12); @@ -828,7 +830,7 @@ describe("spy", function () { }); it("is true if called with new on custom constructor", function () { - function MyThing() {} + function MyThing() { return; } MyThing.prototype = {}; var ns = { MyThing: MyThing }; createSpy(ns, "MyThing"); @@ -935,7 +937,7 @@ describe("spy", function () { }); it("stacks up objects", function () { - function MyConstructor() {} + function MyConstructor() { return; } var objects = [{}, [], new MyConstructor(), { id: 243 }]; this.spy(); this.spy.call(objects[0]); @@ -1530,7 +1532,7 @@ describe("spy", function () { }); it("returns true when returned value once", function () { - var values = [{}, 2, "hey", function () {}]; + var values = [{}, 2, "hey", function () { return; }]; var spy = createSpy.create(function () { return values[spy.callCount]; }); @@ -1544,7 +1546,7 @@ describe("spy", function () { }); it("returns false when value is never returned", function () { - var values = [{}, 2, "hey", function () {}]; + var values = [{}, 2, "hey", function () { return; }]; var spy = createSpy.create(function () { return values[spy.callCount]; }); @@ -1627,7 +1629,7 @@ describe("spy", function () { }); it("contains the created object for spied constructors", function () { - var Spy = createSpy.create(function () { }); + var Spy = createSpy.create(function () { return; }); var result = new Spy(); @@ -2126,7 +2128,7 @@ describe("spy", function () { }); it("includes spy name in error message", function () { - var api = { someMethod: function () {} }; + var api = { someMethod: function () { return; } }; var spy = createSpy(api, "someMethod"); assert.exception( @@ -2225,7 +2227,7 @@ describe("spy", function () { }); it("includes spy name in error message", function () { - var api = { someMethod: function () {} }; + var api = { someMethod: function () { return; } }; var spy = createSpy(api, "someMethod"); var thisObj = { name1: "value1", name2: "value2" }; @@ -2332,7 +2334,7 @@ describe("spy", function () { }); it("includes spy name in error message", function () { - var api = { someMethod: function () {} }; + var api = { someMethod: function () { return; } }; var spy = createSpy(api, "someMethod"); assert.exception( @@ -2420,7 +2422,7 @@ describe("spy", function () { }); it("includes spy name in error message", function () { - var api = { someMethod: function () {} }; + var api = { someMethod: function () { return; } }; var spy = createSpy(api, "someMethod"); var thisObj = { name1: "value1", name2: "value2" }; @@ -2501,7 +2503,7 @@ describe("spy", function () { }); it("includes spy name in error message", function () { - var api = { someMethod: function () {} }; + var api = { someMethod: function () { return; } }; var spy = createSpy(api, "someMethod"); assert.exception( @@ -2596,7 +2598,7 @@ describe("spy", function () { }); it("includes spy name in error message", function () { - var api = { someMethod: function () {} }; + var api = { someMethod: function () { return; } }; var spy = createSpy(api, "someMethod"); var thisObj = { name1: "value1", name2: "value2" }; @@ -2738,7 +2740,7 @@ describe("spy", function () { }); it("matches the function length", function () { - var api = { someMethod: function (a, b, c) {} }; // eslint-disable-line no-unused-vars + var api = { someMethod: function (a, b, c) { return; } }; // eslint-disable-line no-unused-vars var spy = createSpy(api, "someMethod"); assert.equals(spy.length, 3); diff --git a/test/stub-test.js b/test/stub-test.js index 0fcea0333..2cc188fa8 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -1120,7 +1120,7 @@ describe("stub", function () { describe(".objectMethod", function () { beforeEach(function () { - this.method = function () {}; + this.method = function () { return; }; this.object = { method: this.method }; }); @@ -1181,7 +1181,7 @@ describe("stub", function () { }); it("successfully stubs falsey properties", function () { - var obj = { 0: function () { } }; + var obj = { 0: function () { return; } }; createStub(obj, 0).callsFake(function () { return "stubbed value"; @@ -1192,7 +1192,7 @@ describe("stub", function () { it("does not stub function object", function () { assert.exception(function () { - createStub(function () {}); + createStub(function () { return; }); }); }); }); @@ -1200,9 +1200,9 @@ describe("stub", function () { describe("everything", function () { it("stubs all methods of object without property", function () { var obj = { - func1: function () {}, - func2: function () {}, - func3: function () {} + func1: function () { return; }, + func2: function () { return; }, + func3: function () { return; } }; createStub(obj); @@ -1213,8 +1213,8 @@ describe("stub", function () { }); it("stubs prototype methods", function () { - function Obj() {} - Obj.prototype.func1 = function () {}; + function Obj() { return; } + Obj.prototype.func1 = function () { return; }; var obj = new Obj(); createStub(obj); @@ -1237,12 +1237,12 @@ describe("stub", function () { it("handles non-enumerable properties", function () { var obj = { - func1: function () {}, - func2: function () {} + func1: function () { return; }, + func2: function () { return; } }; Object.defineProperty(obj, "func3", { - value: function () {}, + value: function () { return; }, writable: true, configurable: true }); @@ -1255,9 +1255,9 @@ describe("stub", function () { }); it("handles non-enumerable properties on prototypes", function () { - function Obj() {} + function Obj() { return; } Object.defineProperty(Obj.prototype, "func1", { - value: function () {}, + value: function () { return; }, writable: true, configurable: true }); @@ -1281,10 +1281,10 @@ describe("stub", function () { it("does not fail on overrides", function () { var parent = { - func: function () {} + func: function () { return; } }; var child = Object.create(parent); - child.func = function () {}; + child.func = function () { return; }; refute.exception(function () { createStub(child); @@ -1320,7 +1320,7 @@ describe("stub", function () { describe("stubbed function", function () { it("has toString method", function () { - var obj = { meth: function () {} }; + var obj = { meth: function () { return; } }; createStub(obj, "meth"); assert.equals(obj.meth.toString(), "meth"); @@ -1360,7 +1360,7 @@ describe("stub", function () { }); it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () {} }; + var myObj = { somethingAwesome: function () { return; } }; var stub = createStub(myObj, "somethingAwesome").yields(); assert.exception( @@ -1476,7 +1476,7 @@ describe("stub", function () { }); it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () {} }; + var myObj = { somethingAwesome: function () { return; } }; var stub = createStub(myObj, "somethingAwesome").yieldsRight(); assert.exception( @@ -1605,7 +1605,7 @@ describe("stub", function () { }); it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () {} }; + var myObj = { somethingAwesome: function () { return; } }; var stub = createStub(myObj, "somethingAwesome").yieldsOn(this.fakeContext); assert.exception( @@ -1743,7 +1743,7 @@ describe("stub", function () { }); it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () {} }; + var myObj = { somethingAwesome: function () { return; } }; var stub = createStub(myObj, "somethingAwesome").yieldsTo("success"); assert.exception( @@ -1890,7 +1890,7 @@ describe("stub", function () { }); it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () {} }; + var myObj = { somethingAwesome: function () { return; } }; var stub = createStub(myObj, "somethingAwesome").yieldsToOn("success", this.fakeContext); assert.exception( @@ -2493,7 +2493,7 @@ describe("stub", function () { describe(".reset", function () { it("resets behavior", function () { - var obj = { a: function () {} }; + var obj = { a: function () { return; } }; var spy = createSpy(); createStub(obj, "a").callsArg(1); @@ -2683,7 +2683,7 @@ describe("stub", function () { }); it("matches the function length", function () { - var api = { someMethod: function (a, b, c) {} }; // eslint-disable-line no-unused-vars + var api = { someMethod: function (a, b, c) { return; } }; // eslint-disable-line no-unused-vars var stub = createStub(api, "someMethod"); assert.equals(stub.length, 3); @@ -2692,8 +2692,8 @@ describe("stub", function () { describe(".createStubInstance", function () { it("stubs existing methods", function () { - var Class = function () {}; - Class.prototype.method = function () {}; + var Class = function () { return; }; + Class.prototype.method = function () { return; }; var stub = createStubInstance(Class); stub.method.returns(3); @@ -2701,7 +2701,7 @@ describe("stub", function () { }); it("doesn't stub fake methods", function () { - var Class = function () {}; + var Class = function () { return; }; var stub = createStubInstance(Class); assert.exception(function () { @@ -2714,7 +2714,7 @@ describe("stub", function () { var c = a + b; throw c; }; - Class.prototype.method = function () {}; + Class.prototype.method = function () { return; }; var stub = createStubInstance(Class); refute.exception(function () { @@ -2724,7 +2724,7 @@ describe("stub", function () { it("retains non function values", function () { var TYPE = "some-value"; - var Class = function () {}; + var Class = function () { return; }; Class.prototype.type = TYPE; var stub = createStubInstance(Class); @@ -2737,7 +2737,7 @@ describe("stub", function () { throw "error"; } }; - var Class = function () {}; + var Class = function () { return; }; Class.prototype = proto; var stub = createStubInstance(Class); @@ -2758,8 +2758,8 @@ describe("stub", function () { }); it("allows providing optional overrides", function () { - var Class = function () {}; - Class.prototype.method = function () {}; + var Class = function () { return; }; + Class.prototype.method = function () { return; }; var stub = createStubInstance(Class, { method: createStub().returns(3) @@ -2769,8 +2769,8 @@ describe("stub", function () { }); it("allows providing optional returned values", function () { - var Class = function () {}; - Class.prototype.method = function () {}; + var Class = function () { return; }; + Class.prototype.method = function () { return; }; var stub = createStubInstance(Class, { method: 3 @@ -2780,8 +2780,8 @@ describe("stub", function () { }); it("throws an exception when trying to override non-existing property", function () { - var Class = function () {}; - Class.prototype.method = function () {}; + var Class = function () { return; }; + Class.prototype.method = function () { return; }; assert.exception(function () { createStubInstance(Class, { @@ -3073,7 +3073,7 @@ describe("stub", function () { }); it("allows stubbing function static properties", function () { - var myFunc = function () {}; + var myFunc = function () { return; }; myFunc.prop = "rawString"; createStub(myFunc, "prop").value("newString"); @@ -3081,7 +3081,7 @@ describe("stub", function () { }); it("allows restoring function static properties", function () { - var myFunc = function () {}; + var myFunc = function () { return; }; myFunc.prop = "rawString"; var stub = createStub(myFunc, "prop").value("newString"); diff --git a/test/util/core/called-in-order-test.js b/test/util/core/called-in-order-test.js index a19df7918..4d99a2f84 100644 --- a/test/util/core/called-in-order-test.js +++ b/test/util/core/called-in-order-test.js @@ -5,9 +5,9 @@ var calledInOrder = require("../../../lib/sinon/util/core/called-in-order"); var sinonStub = require("../../../lib/sinon/stub"); var assert = referee.assert; -var testObject1 = {someFunction: function () {}}; -var testObject2 = {otherFunction: function () {}}; -var testObject3 = {thirdFunction: function () {}}; +var testObject1 = {someFunction: function () { return; }}; +var testObject2 = {otherFunction: function () { return; }}; +var testObject3 = {thirdFunction: function () { return; }}; function testMethod() { testObject1.someFunction(); diff --git a/test/util/core/deep-equal-test.js b/test/util/core/deep-equal-test.js index 65d16863c..7a9426a63 100644 --- a/test/util/core/deep-equal-test.js +++ b/test/util/core/deep-equal-test.js @@ -46,7 +46,7 @@ describe("util/core/deepEqual", function () { }); it("passes same function", function () { - var func = function () {}; + var func = function () { return; }; assert(deepEqual(func, func)); }); @@ -245,7 +245,7 @@ describe("util/core/deepEqual", function () { } it("passes deep objects", function () { - var func = function () {}; + var func = function () { return; }; var obj1 = { a: 1, diff --git a/test/util/core/function-to-string-test.js b/test/util/core/function-to-string-test.js index 8ee68daf3..91433ffff 100644 --- a/test/util/core/function-to-string-test.js +++ b/test/util/core/function-to-string-test.js @@ -7,7 +7,7 @@ var assert = referee.assert; describe("util/core/functionToString", function () { it("returns function's displayName property", function () { - var fn = function () {}; + var fn = function () { return; }; fn.displayName = "Larry"; assert.equals(functionToString.call(fn), "Larry"); diff --git a/test/util/core/get-next-tick-test.js b/test/util/core/get-next-tick-test.js index 90efe66d4..3c0a90ba1 100644 --- a/test/util/core/get-next-tick-test.js +++ b/test/util/core/get-next-tick-test.js @@ -7,14 +7,14 @@ var assert = referee.assert; describe("util/core/get-next-tick", function () { it("should use process.nextTick when available", function () { var mockProcess = { - nextTick: function () {} + nextTick: function () { return; } }; assert.same(getNextTick(mockProcess), mockProcess.nextTick); }); it("should use setImmediate when process.nextTick is not available", function () { - function mockSetImmediate() {} + function mockSetImmediate() { return; } assert.same(getNextTick(undefined, mockSetImmediate), mockSetImmediate); }); diff --git a/test/util/core/restore-test.js b/test/util/core/restore-test.js index 2f971567c..8e33635b5 100644 --- a/test/util/core/restore-test.js +++ b/test/util/core/restore-test.js @@ -7,9 +7,9 @@ var assert = referee.assert; describe("util/core/restore", function () { it("restores all methods of supplied object", function () { - var methodA = function () {}; - var methodB = function () {}; - var nonEnumerableMethod = function () {}; + var methodA = function () { return; }; + var methodB = function () { return; }; + var nonEnumerableMethod = function () { return; }; var obj = { methodA: methodA, methodB: methodB, nonEnumerableMethod: nonEnumerableMethod }; Object.defineProperty(obj, "nonEnumerableMethod", { enumerable: false @@ -24,8 +24,8 @@ describe("util/core/restore", function () { }); it("only restores restorable methods", function () { - var stubbedMethod = function () {}; - var vanillaMethod = function () {}; + var stubbedMethod = function () { return; }; + var vanillaMethod = function () { return; }; var obj = { stubbedMethod: stubbedMethod, vanillaMethod: vanillaMethod }; createStub(obj, "stubbedMethod"); @@ -35,7 +35,7 @@ describe("util/core/restore", function () { }); it("restores a single stubbed method", function () { - var method = function () {}; + var method = function () { return; }; var obj = { method: method }; createStub(obj); diff --git a/test/util/core/typeOf-test.js b/test/util/core/typeOf-test.js index 458cf5b9b..e9f93fe21 100644 --- a/test/util/core/typeOf-test.js +++ b/test/util/core/typeOf-test.js @@ -22,7 +22,7 @@ describe("typeOf", function () { }); it("returns function", function () { - assert.equals(sinonTypeOf(function () {}), "function"); + assert.equals(sinonTypeOf(function () { return; }), "function"); }); it("returns undefined", function () { diff --git a/test/util/core/walk-test.js b/test/util/core/walk-test.js index d81d63bf5..f8f3f1332 100644 --- a/test/util/core/walk-test.js +++ b/test/util/core/walk-test.js @@ -85,7 +85,7 @@ describe("util/core/walk", function () { }); it("should not invoke getters on the original receiving object", function () { - var Target = function Target() {}; + var Target = function Target() { return; }; var getter = createSpy(); Object.defineProperty(Target.prototype, "computedFoo", { enumerable: true, @@ -141,10 +141,10 @@ describe("util/core/walk", function () { it("does not walk the same property twice", function () { var parent = { - func: function parentFunc() {} + func: function parentFunc() { return; } }; var child = Object.create(parent); - child.func = function childFunc() {}; + child.func = function childFunc() { return; }; var iterator = createSpy(); walk(child, iterator); diff --git a/test/util/core/wrap-method-test.js b/test/util/core/wrap-method-test.js index cccb1f604..b428e293d 100644 --- a/test/util/core/wrap-method-test.js +++ b/test/util/core/wrap-method-test.js @@ -9,9 +9,9 @@ var refute = referee.refute; describe("util/core/wrapMethod", function () { beforeEach(function () { - this.method = function () {}; - this.getter = function () {}; - this.setter = function () {}; + this.method = function () { return; }; + this.getter = function () { return; }; + this.setter = function () { return; }; this.object = {method: this.method}; Object.defineProperty(this.object, "property", { get: this.getter, @@ -35,7 +35,7 @@ describe("util/core/wrapMethod", function () { var object = this.object; assert.exception(function () { - wrapMethod(object, "prop", function () {}); + wrapMethod(object, "prop", function () { return; }); }, {name: "TypeError"}); }); @@ -46,7 +46,7 @@ describe("util/core/wrapMethod", function () { object[symbol] = 42; assert.exception(function () { - wrapMethod(object, symbol, function () {}); + wrapMethod(object, symbol, function () { return; }); }, function (err) { return err.message === "Attempted to wrap number property Symbol() as function"; }); @@ -57,12 +57,12 @@ describe("util/core/wrapMethod", function () { var object = this.object; assert.exception(function () { - wrapMethod(object, "prop", function () {}); + wrapMethod(object, "prop", function () { return; }); }); assert.exception( function () { - wrapMethod(object, "prop", function () {}); + wrapMethod(object, "prop", function () { return; }); }, { message: /Attempted to wrap .* property .* as function/ @@ -87,14 +87,14 @@ describe("util/core/wrapMethod", function () { }); it("replaces object method", function () { - wrapMethod(this.object, "method", function () {}); + wrapMethod(this.object, "method", function () { return; }); refute.same(this.method, this.object.method); assert.isFunction(this.object.method); }); it("replaces getter", function () { - wrapMethod(this.object, "property", { get: function () {} }); + wrapMethod(this.object, "property", { get: function () { return; } }); refute.same(this.getter, Object.getOwnPropertyDescriptor(this.object, "property").get); assert.isFunction(Object.getOwnPropertyDescriptor(this.object, "property").get); @@ -102,7 +102,7 @@ describe("util/core/wrapMethod", function () { it("replaces setter", function () { wrapMethod(this.object, "property", { // eslint-disable-line accessor-pairs - set: function () {} + set: function () { return; } }); refute.same(this.setter, Object.getOwnPropertyDescriptor(this.object, "property").set); @@ -110,10 +110,10 @@ describe("util/core/wrapMethod", function () { }); it("throws if method is already wrapped", function () { - wrapMethod(this.object, "method", function () {}); + wrapMethod(this.object, "method", function () { return; }); assert.exception(function () { - wrapMethod(this.object, "method", function () {}); + wrapMethod(this.object, "method", function () { return; }); }, {name: "TypeError"}); }); @@ -121,11 +121,11 @@ describe("util/core/wrapMethod", function () { if (typeof Symbol === "function") { var symbol = Symbol(); var object = {}; - object[symbol] = function () {}; - wrapMethod(object, symbol, function () {}); + object[symbol] = function () { return; }; + wrapMethod(object, symbol, function () { return; }); assert.exception(function () { - wrapMethod(object, symbol, function () {}); + wrapMethod(object, symbol, function () { return; }); }, function (err) { return err.message === "Attempted to wrap Symbol() which is already wrapped"; }); @@ -133,10 +133,10 @@ describe("util/core/wrapMethod", function () { }); it("throws if property descriptor is already wrapped", function () { - wrapMethod(this.object, "property", { get: function () {} }); + wrapMethod(this.object, "property", { get: function () { return; } }); assert.exception(function () { - wrapMethod(this.object, "property", { get: function () {} }); + wrapMethod(this.object, "property", { get: function () { return; } }); }, {name: "TypeError"}); }); @@ -144,7 +144,7 @@ describe("util/core/wrapMethod", function () { var object = { method: createSpy() }; assert.exception(function () { - wrapMethod(object, "method", function () {}); + wrapMethod(object, "method", function () { return; }); }, {name: "TypeError"}); }); @@ -155,7 +155,7 @@ describe("util/core/wrapMethod", function () { object[symbol] = createSpy(); assert.exception(function () { - wrapMethod(object, symbol, function () {}); + wrapMethod(object, symbol, function () { return; }); }, function (err) { return err.message === "Attempted to wrap Symbol() which is already spied on"; }); @@ -183,14 +183,14 @@ describe("util/core/wrapMethod", function () { }); it("throws with stack trace showing original wrapMethod call", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; wrapMethod(object, "method", function () { return "original"; }); assert.exception( function () { - wrapMethod(object, "method", function () {}); + wrapMethod(object, "method", function () { return; }); }, { stack: ":STACK2:\n--------------\n:STACK1:" @@ -202,25 +202,25 @@ describe("util/core/wrapMethod", function () { if (typeof window !== "undefined") { describe("in browser", function () { it("does not throw if object is window object", function () { - window.sinonTestMethod = function () {}; + window.sinonTestMethod = function () { return; }; refute.exception(function () { - wrapMethod(window, "sinonTestMethod", function () {}); + wrapMethod(window, "sinonTestMethod", function () { return; }); }); }); }); } it("mirrors function properties", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; object.method.prop = 42; - wrapMethod(object, "method", function () {}); + wrapMethod(object, "method", function () { return; }); assert.equals(object.method.prop, 42); }); it("does not mirror and overwrite existing properties", function () { - var object = { method: function () {} }; + var object = { method: function () { return; } }; object.method.called = 42; createStub(object, "method"); @@ -230,24 +230,24 @@ describe("util/core/wrapMethod", function () { describe("wrapped method", function () { beforeEach(function () { - this.method = function () {}; + this.method = function () { return; }; this.object = { method: this.method }; }); it("defines restore method", function () { - wrapMethod(this.object, "method", function () {}); + wrapMethod(this.object, "method", function () { return; }); assert.isFunction(this.object.method.restore); }); it("returns wrapper", function () { - var wrapper = wrapMethod(this.object, "method", function () {}); + var wrapper = wrapMethod(this.object, "method", function () { return; }); assert.same(this.object.method, wrapper); }); it("restore brings back original method", function () { - wrapMethod(this.object, "method", function () {}); + wrapMethod(this.object, "method", function () { return; }); this.object.method.restore(); assert.same(this.object.method, this.method); @@ -256,21 +256,21 @@ describe("util/core/wrapMethod", function () { describe("wrapped prototype method", function () { beforeEach(function () { - this.type = function () {}; - this.type.prototype.method = function () {}; + this.type = function () { return; }; + this.type.prototype.method = function () { return; }; this.object = new this.type(); //eslint-disable-line new-cap }); it("wrap adds owned property", function () { - var wrapper = wrapMethod(this.object, "method", function () {}); + var wrapper = wrapMethod(this.object, "method", function () { return; }); assert.same(this.object.method, wrapper); assert(this.object.hasOwnProperty("method")); }); it("restore removes owned property", function () { - wrapMethod(this.object, "method", function () {}); + wrapMethod(this.object, "method", function () { return; }); this.object.method.restore(); assert.same(this.object.method, this.type.prototype.method); diff --git a/test/util/fake-timers-test.js b/test/util/fake-timers-test.js index be7151cda..7df6685e5 100644 --- a/test/util/fake-timers-test.js +++ b/test/util/fake-timers-test.js @@ -103,7 +103,7 @@ describe("fakeTimers.clock", function () { }); it("returns numeric id or object with numeric id", function () { - var result = this.clock.setImmediate(function () { }); + var result = this.clock.setImmediate(function () { return; }); if (typeof result === "object") { assert.isNumber(result.id); @@ -639,8 +639,8 @@ describe("fakeTimers.clock", function () { var realDate = new Date(); // eslint-disable-next-line no-global-assign - Date = function () {}; - this.global.Date = function () {}; + Date = function () { return; }; + this.global.Date = function () { return; }; var date = new this.clock.Date(); @@ -892,7 +892,7 @@ describe("fakeTimers.clock", function () { var to = setTimeout(stub, 1000); - if (typeof (setTimeout(function () {}, 0)) === "object") { + if (typeof (setTimeout(function () { return; }, 0)) === "object") { assert.isNumber(to.id); assert.isFunction(to.ref); assert.isFunction(to.unref); @@ -976,7 +976,7 @@ describe("fakeTimers.clock", function () { it("deletes global property on restore if it was inherited onto the global object", function () { // Give the global object an inherited 'tick' method delete this.global.tick; - this.global.__proto__.tick = function () { }; + this.global.__proto__.tick = function () { return; }; if (!this.global.hasOwnProperty("tick")) { this.clock = fakeTimers.useFakeTimers({toFake: ["tick"]}); @@ -995,7 +995,7 @@ describe("fakeTimers.clock", function () { it("restores global property on restore if it is present on the global object itself", function () { // Directly give the global object a tick method - this.global.tick = function () { }; + this.global.tick = function () { return; }; this.clock = fakeTimers.useFakeTimers({toFake: ["tick"]}); assert.isTrue(this.global.hasOwnProperty("tick")); @@ -1021,7 +1021,7 @@ describe("fakeTimers.clock", function () { }); it("decide on Date.now support at call-time when supported", function () { - this.global.Date.now = function () {}; + this.global.Date.now = function () { return; }; this.clock = fakeTimers.useFakeTimers(0); assert.equals(typeof Date.now, "function"); @@ -1035,7 +1035,7 @@ describe("fakeTimers.clock", function () { }); it("mirrors custom Date properties", function () { - var f = function () { }; + var f = function () { return; }; this.global.Date.format = f; fakeTimers.useFakeTimers(); From 6e63ba8111ca95b587e65343c262c47500768a55 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 20:27:21 +0200 Subject: [PATCH 08/21] Fix lint violations for no-eq-null --- lib/sinon/match.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sinon/match.js b/lib/sinon/match.js index a92faa5aa..a7044d1d5 100644 --- a/lib/sinon/match.js +++ b/lib/sinon/match.js @@ -31,7 +31,7 @@ function assertType(value, type, name) { } function assertMethodExists(value, method, name, methodPath) { - if (value[method] == null) { + if (typeof value[method] === "undefined") { throw new TypeError("Expected " + name + " to have method " + methodPath); } } From 6204505a4e324d30ab58e3b1dbfdea2e4ec637ed Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 20:33:14 +0200 Subject: [PATCH 09/21] Fix lint violations for no-implicit-coercion --- lib/sinon/assert.js | 2 +- lib/sinon/blob.js | 2 +- lib/sinon/call.js | 2 +- lib/sinon/match.js | 6 +++--- lib/sinon/util/core/wrap-method.js | 2 +- test/sandbox-test.js | 2 +- test/util/fake-timers-test.js | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index f7e0e35c1..372646f6a 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -157,7 +157,7 @@ assert = { var o = options || {}; var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix; - var includeFail = typeof o.includeFail === "undefined" || !!o.includeFail; + var includeFail = typeof o.includeFail === "undefined" || Boolean(o.includeFail); var instance = this; forEach(Object.keys(instance), function (method) { diff --git a/lib/sinon/blob.js b/lib/sinon/blob.js index 78a5dd8ba..8f386d231 100644 --- a/lib/sinon/blob.js +++ b/lib/sinon/blob.js @@ -3,7 +3,7 @@ exports.isSupported = (function () { try { - return !!new Blob(); + return Boolean(new Blob()); } catch (e) { return false; } diff --git a/lib/sinon/call.js b/lib/sinon/call.js index 4fdce5b0a..97435612c 100644 --- a/lib/sinon/call.js +++ b/lib/sinon/call.js @@ -77,7 +77,7 @@ var callProto = { threw: function threw(error) { if (typeof error === "undefined" || !this.exception) { - return !!this.exception; + return Boolean(this.exception); } return this.exception === error || this.exception.name === error; diff --git a/lib/sinon/match.js b/lib/sinon/match.js index a7044d1d5..81434f031 100644 --- a/lib/sinon/match.js +++ b/lib/sinon/match.js @@ -177,7 +177,7 @@ match.defined = match(function (actual) { }, "defined"); match.truthy = match(function (actual) { - return !!actual; + return Boolean(actual); }, "truthy"); match.falsy = match(function (actual) { @@ -279,7 +279,7 @@ match.every = function (predicate) { }); } - return !!actual && typeOf(actual.forEach) === "function" && every(actual, function (element) { + return Boolean(actual) && typeOf(actual.forEach) === "function" && every(actual, function (element) { return predicate.test(element); }); }, "every(" + predicate.message + ")"); @@ -297,7 +297,7 @@ match.some = function (predicate) { }); } - return !!actual && typeOf(actual.forEach) === "function" && !every(actual, function (element) { + return Boolean(actual) && typeOf(actual.forEach) === "function" && !every(actual, function (element) { return !predicate.test(element); }); }, "some(" + predicate.message + ")"); diff --git a/lib/sinon/util/core/wrap-method.js b/lib/sinon/util/core/wrap-method.js index 811b95444..55ea77001 100644 --- a/lib/sinon/util/core/wrap-method.js +++ b/lib/sinon/util/core/wrap-method.js @@ -5,7 +5,7 @@ var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnPropert var valueToString = require("@sinonjs/commons").valueToString; function isFunction(obj) { - return typeof obj === "function" || !!(obj && obj.constructor && obj.call && obj.apply); + return typeof obj === "function" || Boolean(obj && obj.constructor && obj.call && obj.apply); } function mirrorProperties(target, source) { diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 3ba146880..05b33c819 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -19,7 +19,7 @@ var sinonAssert = require("../lib/sinon/assert"); var sinonClock = require("../lib/sinon/util/fake_timers"); var supportsAjax = typeof XMLHttpRequest !== "undefined" || typeof ActiveXObject !== "undefined"; -var supportPromise = !!global.Promise; +var supportPromise = Boolean(global.Promise); var globalXHR = global.XMLHttpRequest; var globalAXO = global.ActiveXObject; diff --git a/test/util/fake-timers-test.js b/test/util/fake-timers-test.js index 7df6685e5..b52f1c8c4 100644 --- a/test/util/fake-timers-test.js +++ b/test/util/fake-timers-test.js @@ -1016,8 +1016,8 @@ describe("fakeTimers.clock", function () { it("fake Date constructor should mirror Date's properties", function () { this.clock = fakeTimers.useFakeTimers(0); - assert(!!Date.parse); - assert(!!Date.UTC); + assert(Boolean(Date.parse)); + assert(Boolean(Date.UTC)); }); it("decide on Date.now support at call-time when supported", function () { From 5cc5dd9b6aa0d282756c3889d1062979ace195c2 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 22:28:52 +0200 Subject: [PATCH 10/21] Fix lint violations for no-param-reassign --- lib/sinon/assert.js | 22 ++++++++++++---------- lib/sinon/match.js | 14 ++++++++------ lib/sinon/mock-expectation.js | 11 ++++++----- lib/sinon/spy-formatters.js | 7 ++++--- lib/sinon/spy.js | 19 +++++++++---------- lib/sinon/util/core/called-in-order.js | 12 +++++------- lib/sinon/util/core/get-config.js | 5 ++--- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 372646f6a..6b29c4f86 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -56,15 +56,17 @@ function verifyIsValidAssertion(assertionMethod, assertionArgs) { } function failAssertion(object, msg) { - object = object || global; - var failMethod = object.fail || assert.fail; - failMethod.call(object, msg); + var obj = object || global; + var failMethod = obj.fail || assert.fail; + failMethod.call(obj, msg); } function mirrorPropAsAssertion(name, method, message) { + var msg = message; + var meth = method; if (arguments.length === 2) { - message = method; - method = name; + msg = method; + meth = name; } assert[name] = function (fake) { @@ -75,15 +77,15 @@ function mirrorPropAsAssertion(name, method, message) { verifyIsValidAssertion(name, args); - if (typeof method === "function") { - failed = !method(fake); + if (typeof meth === "function") { + failed = !meth(fake); } else { - failed = typeof fake[method] === "function" ? - !fake[method].apply(fake, args) : !fake[method]; + failed = typeof fake[meth] === "function" ? + !fake[meth].apply(fake, args) : !fake[meth]; } if (failed) { - failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, concat([message], args))); + failAssertion(this, (fake.printf || fake.proxy.printf).apply(fake, concat([msg], args))); } else { assert.pass(name); } diff --git a/lib/sinon/match.js b/lib/sinon/match.js index 81434f031..dfaf2ea74 100644 --- a/lib/sinon/match.js +++ b/lib/sinon/match.js @@ -137,32 +137,34 @@ function match(expectation, message) { } matcher.or = function (m2) { + var matcher2 = m2; if (!arguments.length) { throw new TypeError("Matcher expected"); } else if (!isMatcher(m2)) { - m2 = match(m2); + matcher2 = match(m2); } var m1 = this; var or = Object.create(matcher); or.test = function (actual) { - return m1.test(actual) || m2.test(actual); + return m1.test(actual) || matcher2.test(actual); }; - or.message = m1.message + ".or(" + m2.message + ")"; + or.message = m1.message + ".or(" + matcher2.message + ")"; return or; }; matcher.and = function (m2) { + var matcher2 = m2; if (!arguments.length) { throw new TypeError("Matcher expected"); } else if (!isMatcher(m2)) { - m2 = match(m2); + matcher2 = match(m2); } var m1 = this; var and = Object.create(matcher); and.test = function (actual) { - return m1.test(actual) && m2.test(actual); + return m1.test(actual) && matcher2.test(actual); }; - and.message = m1.message + ".and(" + m2.message + ")"; + and.message = m1.message + ".and(" + matcher2.message + ")"; return and; }; diff --git a/lib/sinon/mock-expectation.js b/lib/sinon/mock-expectation.js index 1f71dff45..61fab1a32 100644 --- a/lib/sinon/mock-expectation.js +++ b/lib/sinon/mock-expectation.js @@ -203,23 +203,24 @@ var mockExpectation = { return true; } - args = args || []; + // eslint-disable-next-line no-underscore-dangle + var _args = args || []; - if (args.length < expectedArguments.length) { + if (_args.length < expectedArguments.length) { return false; } if (this.expectsExactArgCount && - args.length !== expectedArguments.length) { + _args.length !== expectedArguments.length) { return false; } return every(expectedArguments, function (expectedArgument, i) { - if (!verifyMatcher(expectedArgument, args[i])) { + if (!verifyMatcher(expectedArgument, _args[i])) { return false; } - if (!deepEqual(expectedArgument, args[i])) { + if (!deepEqual(expectedArgument, _args[i])) { return false; } diff --git a/lib/sinon/spy-formatters.js b/lib/sinon/spy-formatters.js index 064d995e5..3e0d6d903 100644 --- a/lib/sinon/spy-formatters.js +++ b/lib/sinon/spy-formatters.js @@ -12,13 +12,14 @@ var map = arrayProto.map; var push = arrayProto.push; function colorSinonMatchText(matcher, calledArg, calledArgMessage) { + var calledArgumentMessage = calledArgMessage; if (!matcher.test(calledArg)) { matcher.message = color.red(matcher.message); - if (calledArgMessage) { - calledArgMessage = color.green(calledArgMessage); + if (calledArgumentMessage) { + calledArgumentMessage = color.green(calledArgumentMessage); } } - return calledArgMessage + " " + matcher.message; + return calledArgumentMessage + " " + matcher.message; } function colorDiffText(diff) { diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index de65b1b7d..1d36815ce 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -150,27 +150,26 @@ var spyApi = { create: function create(func, spyLength) { var name; + var funk = func; - if (typeof func !== "function") { - func = function () { + + if (typeof funk !== "function") { + funk = function () { return; }; } else { - name = functionName(func); - } - - if (!spyLength) { - spyLength = func.length; + name = functionName(funk); } - var proxy = createProxy(func, spyLength); + var length = spyLength || funk.length; + var proxy = createProxy(funk, length); extend(proxy, spy); delete proxy.create; - extend(proxy, func); + extend(proxy, funk); proxy.resetHistory(); - proxy.prototype = func.prototype; + proxy.prototype = funk.prototype; proxy.displayName = name || "spy"; proxy.toString = functionToString; proxy.instantiateFake = spy.create; diff --git a/lib/sinon/util/core/called-in-order.js b/lib/sinon/util/core/called-in-order.js index 862684391..b6b90679d 100644 --- a/lib/sinon/util/core/called-in-order.js +++ b/lib/sinon/util/core/called-in-order.js @@ -4,6 +4,8 @@ var every = Array.prototype.every; module.exports = function calledInOrder(spies) { var callMap = {}; + // eslint-disable-next-line no-underscore-dangle + var _spies = arguments.length > 1 ? arguments : spies; function hasCallsLeft(spy) { if (callMap[spy.id] === undefined) { @@ -13,15 +15,11 @@ module.exports = function calledInOrder(spies) { return callMap[spy.id] < spy.callCount; } - if (arguments.length > 1) { - spies = arguments; - } - - return every.call(spies, function checkAdjacentCalls(spy, i) { + return every.call(_spies, function checkAdjacentCalls(spy, i) { var calledBeforeNext = true; - if (i !== spies.length - 1) { - calledBeforeNext = spy.calledBefore(spies[i + 1]); + if (i !== _spies.length - 1) { + calledBeforeNext = spy.calledBefore(_spies[i + 1]); } if (hasCallsLeft(spy) && calledBeforeNext) { diff --git a/lib/sinon/util/core/get-config.js b/lib/sinon/util/core/get-config.js index 02227e3d0..0936c62a7 100644 --- a/lib/sinon/util/core/get-config.js +++ b/lib/sinon/util/core/get-config.js @@ -6,12 +6,11 @@ var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnPropert module.exports = function getConfig(custom) { var config = {}; var prop; - - custom = custom || {}; + var kustom = custom || {}; for (prop in defaultConfig) { if (hasOwnProperty(defaultConfig, prop)) { - config[prop] = hasOwnProperty(custom, prop) ? custom[prop] : defaultConfig[prop]; + config[prop] = hasOwnProperty(kustom, prop) ? kustom[prop] : defaultConfig[prop]; } } From 6b6746c95f73a4ff1bbf9471ac0352c7222c25ac Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 22:30:46 +0200 Subject: [PATCH 11/21] Fix lint violations for no-self-compare --- lib/sinon/util/core/deep-equal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/sinon/util/core/deep-equal.js b/lib/sinon/util/core/deep-equal.js index d1d2b6270..b87df09d7 100644 --- a/lib/sinon/util/core/deep-equal.js +++ b/lib/sinon/util/core/deep-equal.js @@ -9,6 +9,7 @@ var join = arrayProto.join; var sort = arrayProto.sort; function isReallyNaN(val) { + // eslint-disable-next-line no-self-compare return val !== val; } From 91fb220a27589afee087c4ad36169a24735da2c2 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 22:35:53 +0200 Subject: [PATCH 12/21] Fix lint violations for no-throw-literal --- test/sandbox-test.js | 2 +- test/spy-test.js | 3 ++- test/stub-test.js | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 05b33c819..92a7d4d9f 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -214,7 +214,7 @@ describe("Sandbox", function () { it("has no side effects on the prototype", function () { var proto = { method: function () { - throw "error"; + throw new Error("error"); } }; var Class = function () { return; }; diff --git a/test/spy-test.js b/test/spy-test.js index e6ff962ea..47ed12f3f 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -1318,6 +1318,7 @@ describe("spy", function () { }); this.spyWithStringError = createSpy.create(function () { + // eslint-disable-next-line no-throw-literal throw "error"; }); }); @@ -1916,7 +1917,7 @@ describe("spy", function () { it("is tracked even if exceptions are thrown", function () { var spy = createSpy(function () { - throw "an exception"; + throw new Error("an exception"); }); assert.exception(spy); diff --git a/test/stub-test.js b/test/stub-test.js index 2cc188fa8..abe66fa48 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -2734,7 +2734,7 @@ describe("stub", function () { it("has no side effects on the prototype", function () { var proto = { method: function () { - throw "error"; + throw new Error("error"); } }; var Class = function () { return; }; From 8e3d7985f596baa56144e998ecfb1e18c5c51182 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 22:40:38 +0200 Subject: [PATCH 13/21] Fix lint violations for no-useless-call --- lib/sinon/create-sandbox.js | 2 +- lib/sinon/sandbox.js | 2 +- lib/sinon/spy.js | 2 +- test/sandbox-test.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/sinon/create-sandbox.js b/lib/sinon/create-sandbox.js index e636f057f..aa637f8df 100644 --- a/lib/sinon/create-sandbox.js +++ b/lib/sinon/create-sandbox.js @@ -19,7 +19,7 @@ function prepareSandboxFromConfig(config) { if (config.useFakeTimers) { if (typeof config.useFakeTimers === "object") { - sandbox.useFakeTimers.call(sandbox, config.useFakeTimers); + sandbox.useFakeTimers(config.useFakeTimers); } else { sandbox.useFakeTimers(); } diff --git a/lib/sinon/sandbox.js b/lib/sinon/sandbox.js index 416c7f75a..c4f03e2bd 100644 --- a/lib/sinon/sandbox.js +++ b/lib/sinon/sandbox.js @@ -55,7 +55,7 @@ function Sandbox() { if (typeof constructor !== "function") { throw new TypeError("The constructor should be a function."); } - return this.stub.call(this, Object.create(constructor.prototype)); + return this.stub(Object.create(constructor.prototype)); }; sandbox.inject = function inject(obj) { diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 1d36815ce..207dd2af4 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -387,7 +387,7 @@ var spyApi = { formatter = spyApi.formatters[specifyer]; if (typeof formatter === "function") { - return String(formatter.call(null, spyInstance, args)); + return String(formatter(spyInstance, args)); } else if (!isNaN(parseInt(specifyer, 10))) { return sinonFormat(args[specifyer - 1]); } diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 92a7d4d9f..982d533cc 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -1483,8 +1483,8 @@ describe("Sandbox", function () { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); - fakes.push.call(fakes, {verify: sinonSpy()}); - fakes.push.call(fakes, {verify: sinonSpy()}); + fakes.push({verify: sinonSpy()}); + fakes.push({verify: sinonSpy()}); sandbox.verify(); From 10885136756ecfbc01a95e3946e31b9a2f7b4828 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 22:49:47 +0200 Subject: [PATCH 14/21] Fix lint violations for wrap-iife --- lib/sinon/util/core/extend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sinon/util/core/extend.js b/lib/sinon/util/core/extend.js index d85bd4a94..cac6451b0 100644 --- a/lib/sinon/util/core/extend.js +++ b/lib/sinon/util/core/extend.js @@ -49,7 +49,7 @@ var hasDontEnumBug = (function () { } } return join(result, "") !== "0123456789"; -})(); +}()); /* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will * override properties in previous sources. From b7c93b6f64de531ba349deba48d5baa6071ec674 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 23:52:31 +0200 Subject: [PATCH 15/21] Also use no-native-reassign, as that's still in the prettier config somewhere --- test/util/core/wrap-method-test.js | 6 +++--- test/util/fake-timers-test.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/util/core/wrap-method-test.js b/test/util/core/wrap-method-test.js index b428e293d..db6c87830 100644 --- a/test/util/core/wrap-method-test.js +++ b/test/util/core/wrap-method-test.js @@ -169,16 +169,16 @@ describe("util/core/wrapMethod", function () { var i = 0; - // eslint-disable-next-line no-global-assign + // eslint-disable-next-line no-global-assign, no-native-reassign Error = TypeError = function () { this.stack = ":STACK" + ++i + ":"; }; }); afterEach(function () { - // eslint-disable-next-line no-global-assign + // eslint-disable-next-line no-global-assign, no-native-reassign Error = this.oldError; - // eslint-disable-next-line no-global-assign + // eslint-disable-next-line no-global-assign, no-native-reassign TypeError = this.oldTypeError; }); diff --git a/test/util/fake-timers-test.js b/test/util/fake-timers-test.js index b52f1c8c4..6728ed645 100644 --- a/test/util/fake-timers-test.js +++ b/test/util/fake-timers-test.js @@ -638,7 +638,7 @@ describe("fakeTimers.clock", function () { it("creates real Date objects when Date constructor is gone", function () { var realDate = new Date(); - // eslint-disable-next-line no-global-assign + // eslint-disable-next-line no-global-assign, no-native-reassign Date = function () { return; }; this.global.Date = function () { return; }; From 5730481f7d7b9f2f0e6674b6449fafdfe4ee1e03 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Mon, 8 Oct 2018 23:52:53 +0200 Subject: [PATCH 16/21] Add prettier --- .eslintrc.yml | 6 +++++- .prettierrc | 4 ++++ package-lock.json | 53 ++++++++++++++++++++++++++++++++++++++++++++--- package.json | 3 +++ 4 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc.yml b/.eslintrc.yml index 0dd583b11..691085d18 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -1,4 +1,6 @@ -extends: sinon +extends: + - sinon + - plugin:prettier/recommended globals: ArrayBuffer: false @@ -10,8 +12,10 @@ globals: plugins: - ie11 - local-rules + - prettier rules: + prettier/prettier: error ie11/no-collection-args: error ie11/no-for-in-const: error ie11/no-loop-func: warn diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..e8980d15c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "printWidth": 120, + "tabWidth": 4 +} diff --git a/package-lock.json b/package-lock.json index 97d067a89..e15b96060 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1677,9 +1677,9 @@ } }, "debug": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.0.1.tgz", - "integrity": "sha512-K23FHJ/Mt404FSlp6gSZCevIbTMLX0j3fmHhUEhQ3Wq0FMODW3+cUSoLdy1Gx4polAf4t/lphhmHH35BB8cLYw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.0.tgz", + "integrity": "sha512-heNPJUJIqC+xB6ayLAMHaIrmN9HKa7aQO8MGqKpvCA+uJYVcvR6l5kgdrhRuwPFHU7P5/A1w0BjByPHwpfTDKg==", "dev": true, "requires": { "ms": "^2.1.1" @@ -1709,6 +1709,23 @@ } } }, + "eslint-config-prettier": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-3.1.0.tgz", + "integrity": "sha512-QYGfmzuc4q4J6XIhlp8vRKdI/fI0tQfQPy1dME3UOLprE+v4ssH/3W9LM2Q7h5qBcy5m0ehCrBDU2YF8q6OY8w==", + "dev": true, + "requires": { + "get-stdin": "^6.0.0" + }, + "dependencies": { + "get-stdin": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "dev": true + } + } + }, "eslint-config-sinon": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/eslint-config-sinon/-/eslint-config-sinon-1.0.3.tgz", @@ -1739,6 +1756,15 @@ "ramda": "^0.25.0" } }, + "eslint-plugin-prettier": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.0.0.tgz", + "integrity": "sha512-4g11opzhqq/8+AMmo5Vc2Gn7z9alZ4JqrbZ+D4i8KlSyxeQhZHlmIrY8U9Akf514MoEhogPa87Jgkq87aZ2Ohw==", + "dev": true, + "requires": { + "prettier-linter-helpers": "^1.0.0" + } + }, "eslint-scope": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-4.0.0.tgz", @@ -1986,6 +2012,12 @@ "integrity": "sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=", "dev": true }, + "fast-diff": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", + "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", + "dev": true + }, "fast-json-stable-stringify": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", @@ -5185,6 +5217,21 @@ "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=", "dev": true }, + "prettier": { + "version": "1.14.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.14.3.tgz", + "integrity": "sha512-qZDVnCrnpsRJJq5nSsiHCE3BYMED2OtsI+cmzIzF1QIfqm5ALf8tEJcO27zV1gKNKRPdhjO0dNWnrzssDQ1tFg==", + "dev": true + }, + "prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "requires": { + "fast-diff": "^1.1.2" + } + }, "pretty-format": { "version": "21.2.1", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-21.2.1.tgz", diff --git a/package.json b/package.json index fc4fb37dd..01938c7c8 100644 --- a/package.json +++ b/package.json @@ -59,10 +59,12 @@ "browserify": "^15.1.0", "dependency-check": "^2.9.1", "eslint": "^5.6.1", + "eslint-config-prettier": "^3.1.0", "eslint-config-sinon": "^1.0.0", "eslint-plugin-ie11": "^1.0.0", "eslint-plugin-local-rules": "^0.1.0", "eslint-plugin-mocha": "^4.2.0", + "eslint-plugin-prettier": "^3.0.0", "esm": "3.0.37", "husky": "^0.14.2", "lint-staged": "^6.0.0", @@ -72,6 +74,7 @@ "mochify-istanbul": "^2.4.2", "native-promise-only": "^0.8.1", "npm-run-all": "^4.1.3", + "prettier": "^1.14.3", "proxyquire": "^1.8.0", "proxyquire-universal": "^1.0.8", "proxyquireify": "^3.2.1", From 6f48865d9bb333c64701f89526d7a487d578561d Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Tue, 9 Oct 2018 00:10:56 +0200 Subject: [PATCH 17/21] Run prettier on all files and fix violations --- build.js | 18 +- eslint-local-rules.js | 23 +- lib/sinon.js | 2 +- lib/sinon/assert.js | 45 +- lib/sinon/behavior.js | 54 +- lib/sinon/blob.js | 4 +- lib/sinon/call.js | 86 +- lib/sinon/collect-own-methods.js | 5 +- lib/sinon/color.js | 10 +- lib/sinon/create-sandbox.js | 4 +- lib/sinon/default-behaviors.js | 31 +- lib/sinon/fake.js | 8 +- lib/sinon/match.js | 222 +-- lib/sinon/mock-expectation.js | 84 +- lib/sinon/mock.js | 51 +- lib/sinon/sandbox.js | 29 +- lib/sinon/spy-formatters.js | 21 +- lib/sinon/spy.js | 172 +- lib/sinon/stub-entire-object.js | 2 +- lib/sinon/stub.js | 60 +- lib/sinon/util/core/deep-equal.js | 11 +- lib/sinon/util/core/deprecated.js | 8 +- lib/sinon/util/core/every.js | 2 +- lib/sinon/util/core/extend.js | 24 +- lib/sinon/util/core/format.js | 2 +- lib/sinon/util/core/is-es-module.js | 7 +- lib/sinon/util/core/iterable-to-string.js | 4 +- lib/sinon/util/core/order-by-first-call.js | 6 +- lib/sinon/util/core/restore.js | 2 +- lib/sinon/util/core/walk.js | 5 +- lib/sinon/util/core/wrap-method.js | 25 +- lib/sinon/util/fake_timers.js | 8 +- test/assert-test.js | 1010 +++++++----- test/behavior-test.js | 6 +- test/call-test.js | 769 +++++---- test/es2015/a-function-module.mjs | 4 +- test/es2015/a-module-with-default.mjs | 4 +- test/es2015/a-module-with-to-string-tag.mjs | 4 +- test/es2015/a-module.mjs | 4 +- test/es2015/check-esm-bundle-is-runnable.js | 4 +- .../es2015/module-support-assessment-test.mjs | 36 +- test/extend-test.js | 16 +- test/fake-test.js | 134 +- test/issues/issues-test.js | 228 +-- test/match-test.js | 732 +++++---- test/mock-test.js | 819 ++++++---- test/sandbox-test.js | 962 ++++++----- test/sinon-test.js | 60 +- test/spy-test.js | 1118 +++++++------ test/stub-test.js | 1429 ++++++++++------- test/test-helper.js | 28 +- test/util/core/called-in-order-test.js | 50 +- test/util/core/color-test.js | 22 +- test/util/core/deep-equal-test.js | 147 +- test/util/core/every-test.js | 14 +- test/util/core/format-test.js | 33 +- test/util/core/function-to-string-test.js | 12 +- test/util/core/get-config-test.js | 8 +- test/util/core/get-next-tick-test.js | 16 +- test/util/core/iterable-to-string-test.js | 14 +- test/util/core/next-tick-test.js | 20 +- test/util/core/restore-test.js | 32 +- test/util/core/times-in-words-test.js | 12 +- test/util/core/typeOf-test.js | 29 +- test/util/core/walk-test.js | 33 +- test/util/core/wrap-method-test.js | 321 ++-- test/util/fake-timers-test.js | 450 +++--- test/webworker/webworker-script.js | 4 +- .../webworker/webworker-support-assessment.js | 9 +- 69 files changed, 5506 insertions(+), 4122 deletions(-) diff --git a/build.js b/build.js index ebef7e9c1..daa8e0a8b 100755 --- a/build.js +++ b/build.js @@ -10,8 +10,7 @@ var pkg = require("./package.json"); var date = new Date().toISOString().split("T")[0]; // Keep the preamble on one line to retain source maps -var preamble = "/* Sinon.JS " + pkg.version + ", " + date - + ", @license BSD-3 */"; +var preamble = "/* Sinon.JS " + pkg.version + ", " + date + ", @license BSD-3 */"; try { fs.mkdirSync("pkg"); @@ -23,15 +22,14 @@ function makeBundle(name, config) { // Create a UMD wrapper and install the "sinon" global: config.standalone = "sinon"; - browserify("./lib/sinon.js", config) - .bundle(function (err, buffer) { - if (err) { - throw err; - } + browserify("./lib/sinon.js", config).bundle(function(err, buffer) { + if (err) { + throw err; + } - var script = preamble + buffer.toString(); - fs.writeFileSync("pkg/" + name + ".js", script); - }); + var script = preamble + buffer.toString(); + fs.writeFileSync("pkg/" + name + ".js", script); + }); } makeBundle("sinon", { diff --git a/eslint-local-rules.js b/eslint-local-rules.js index 4aab34de8..84a9c86d8 100644 --- a/eslint-local-rules.js +++ b/eslint-local-rules.js @@ -2,7 +2,7 @@ function getPrototypeMethods(prototype) { /* eslint-disable local-rules/no-prototype-methods */ - return Object.getOwnPropertyNames(prototype).filter(function (name) { + return Object.getOwnPropertyNames(prototype).filter(function(name) { return typeof prototype[name] === "function" && prototype.hasOwnProperty(name); }); } @@ -25,19 +25,19 @@ module.exports = { schema: [] }, - create: function (context) { + create: function(context) { /** - * Reports if a disallowed property is used in a CallExpression - * @param {ASTNode} node The CallExpression node. - * @returns {void} - */ + * Reports if a disallowed property is used in a CallExpression + * @param {ASTNode} node The CallExpression node. + * @returns {void} + */ function disallowBuiltIns(node) { if ( - node.callee.type !== "MemberExpression" - || node.callee.computed + node.callee.type !== "MemberExpression" || + node.callee.computed || // allow static method calls - || node.callee.object.name === "Array" - || node.callee.object.name === "Object" + node.callee.object.name === "Array" || + node.callee.object.name === "Object" ) { return; } @@ -53,8 +53,7 @@ module.exports = { }, node: node }); - } - else if (DISALLOWED_ARRAY_PROPS.indexOf(propName) > -1) { + } else if (DISALLOWED_ARRAY_PROPS.indexOf(propName) > -1) { context.report({ message: "Do not access {{obj}} prototype method '{{prop}}' from target object.", loc: node.callee.property.loc.start, diff --git a/lib/sinon.js b/lib/sinon.js index 6869a34de..d38175600 100644 --- a/lib/sinon.js +++ b/lib/sinon.js @@ -35,7 +35,7 @@ var apiMethods = { createFakeServer: nise.fakeServer.create.bind(nise.fakeServer), createFakeServerWithClock: nise.fakeServerWithClock.create.bind(nise.fakeServerWithClock), - addBehavior: function (name, fn) { + addBehavior: function(name, fn) { behavior.addBehavior(stub, name, fn); } }; diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 6b29c4f86..5ec323287 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -19,7 +19,7 @@ var assert; function verifyIsStub() { var args = arraySlice(arguments); - forEach(args, function (method) { + forEach(args, function(method) { if (!method) { assert.fail("fake is not a spy"); } @@ -46,8 +46,12 @@ function verifyIsValidAssertion(assertionMethod, assertionArgs) { case "calledTwice": case "calledThrice": if (assertionArgs.length !== 0) { - assert.fail(assertionMethod + - " takes 1 argument but was called with " + (assertionArgs.length + 1) + " arguments"); + assert.fail( + assertionMethod + + " takes 1 argument but was called with " + + (assertionArgs.length + 1) + + " arguments" + ); } break; default: @@ -69,7 +73,7 @@ function mirrorPropAsAssertion(name, method, message) { meth = name; } - assert[name] = function (fake) { + assert[name] = function(fake) { verifyIsStub(fake); var args = arraySlice(arguments, 1); @@ -80,8 +84,7 @@ function mirrorPropAsAssertion(name, method, message) { if (typeof meth === "function") { failed = !meth(fake); } else { - failed = typeof fake[meth] === "function" ? - !fake[meth].apply(fake, args) : !fake[meth]; + failed = typeof fake[meth] === "function" ? !fake[meth].apply(fake, args) : !fake[meth]; } if (failed) { @@ -93,10 +96,7 @@ function mirrorPropAsAssertion(name, method, message) { } function exposedName(prefix, prop) { - return !prefix || /^fail/.test(prop) - ? prop - : prefix + stringSlice(prop, 0, 1).toUpperCase() + stringSlice(prop, 1) - ; + return !prefix || /^fail/.test(prop) ? prop : prefix + stringSlice(prop, 0, 1).toUpperCase() + stringSlice(prop, 1); } assert = { @@ -133,8 +133,7 @@ assert = { // If this fails, we'll just fall back to the blank string } - failAssertion(this, "expected " + expected + " to be " + - "called in order but were called as " + actual); + failAssertion(this, "expected " + expected + " to be " + "called in order but were called as " + actual); } else { assert.pass("callOrder"); } @@ -144,8 +143,7 @@ assert = { verifyIsStub(method); if (method.callCount !== count) { - var msg = "expected %n to be called " + timesInWords(count) + - " but was called %c%C"; + var msg = "expected %n to be called " + timesInWords(count) + " but was called %c%C"; failAssertion(this, method.printf(msg)); } else { assert.pass("callCount"); @@ -158,11 +156,11 @@ assert = { } var o = options || {}; - var prefix = typeof o.prefix === "undefined" && "assert" || o.prefix; + var prefix = (typeof o.prefix === "undefined" && "assert") || o.prefix; var includeFail = typeof o.includeFail === "undefined" || Boolean(o.includeFail); var instance = this; - forEach(Object.keys(instance), function (method) { + forEach(Object.keys(instance), function(method) { if (method !== "expose" && (includeFail || !/^(fail)/.test(method))) { target[exposedName(prefix, method)] = instance[method]; } @@ -188,17 +186,18 @@ assert = { }; mirrorPropAsAssertion("called", "expected %n to have been called at least once but was never called"); -mirrorPropAsAssertion("notCalled", function (spy) { - return !spy.called; -}, "expected %n to not have been called but was called %c%C"); +mirrorPropAsAssertion( + "notCalled", + function(spy) { + return !spy.called; + }, + "expected %n to not have been called but was called %c%C" +); mirrorPropAsAssertion("calledOnce", "expected %n to be called once but was called %c%C"); mirrorPropAsAssertion("calledTwice", "expected %n to be called twice but was called %c%C"); mirrorPropAsAssertion("calledThrice", "expected %n to be called thrice but was called %c%C"); mirrorPropAsAssertion("calledOn", "expected %n to be called with %1 as this but was called with %t"); -mirrorPropAsAssertion( - "alwaysCalledOn", - "expected %n to always be called with %1 as this but was called with %t" -); +mirrorPropAsAssertion("alwaysCalledOn", "expected %n to always be called with %1 as this but was called with %t"); mirrorPropAsAssertion("calledWithNew", "expected %n to be called with new"); mirrorPropAsAssertion("alwaysCalledWithNew", "expected %n to always be called with new"); mirrorPropAsAssertion("calledWith", "expected %n to be called with arguments %D"); diff --git a/lib/sinon/behavior.js b/lib/sinon/behavior.js index 38500cc30..36cbf0773 100644 --- a/lib/sinon/behavior.js +++ b/lib/sinon/behavior.js @@ -39,8 +39,7 @@ function getCallback(behavior, args) { return argumentList[i]; } - if (callArgProp && argumentList[i] && - typeof argumentList[i][callArgProp] === "function") { + if (callArgProp && argumentList[i] && typeof argumentList[i][callArgProp] === "function") { return argumentList[i][callArgProp]; } } @@ -53,12 +52,13 @@ function getCallbackError(behavior, func, args) { var msg; if (behavior.callArgProp) { - msg = functionName(behavior.stub) + - " expected to yield to '" + valueToString(behavior.callArgProp) + + msg = + functionName(behavior.stub) + + " expected to yield to '" + + valueToString(behavior.callArgProp) + "', but no object with such a property was passed."; } else { - msg = functionName(behavior.stub) + - " expected to yield, but no callback was passed."; + msg = functionName(behavior.stub) + " expected to yield, but no callback was passed."; } if (args.length > 0) { @@ -79,9 +79,7 @@ function ensureArgs(name, behavior, args) { if (index >= args.length) { throw new TypeError( - name + " failed: " + (index + 1) - + " arguments required but only " + args.length - + " present" + name + " failed: " + (index + 1) + " arguments required but only " + args.length + " present" ); } } @@ -96,7 +94,7 @@ function callCallback(behavior, args) { } if (behavior.callbackAsync) { - nextTick(function () { + nextTick(function() { func.apply(behavior.callbackContext, behavior.callbackArguments); }); } else { @@ -123,16 +121,18 @@ var proto = { }, isPresent: function isPresent() { - return (typeof this.callArgAt === "number" || - this.exception || - this.exceptionCreator || - typeof this.returnArgAt === "number" || - this.returnThis || - typeof this.resolveArgAt === "number" || - this.resolveThis || - typeof this.throwArgAt === "number" || - this.fakeFn || - this.returnValueDefined); + return ( + typeof this.callArgAt === "number" || + this.exception || + this.exceptionCreator || + typeof this.returnArgAt === "number" || + this.returnThis || + typeof this.resolveArgAt === "number" || + this.resolveThis || + typeof this.throwArgAt === "number" || + this.fakeFn || + this.returnValueDefined + ); }, invoke: function invoke(context, args) { @@ -198,15 +198,15 @@ var proto = { withArgs: function withArgs(/* arguments */) { throw new Error( - "Defining a stub by invoking \"stub.onCall(...).withArgs(...)\" " + - "is not supported. Use \"stub.withArgs(...).onCall(...)\" " + - "to define sequential behavior for calls with certain arguments." + 'Defining a stub by invoking "stub.onCall(...).withArgs(...)" ' + + 'is not supported. Use "stub.withArgs(...).onCall(...)" ' + + "to define sequential behavior for calls with certain arguments." ); } }; function createAsyncVersion(syncFnName) { - return function () { + return function() { var result = this[syncFnName].apply(this, arguments); this.callbackAsync = true; return result; @@ -214,7 +214,7 @@ function createAsyncVersion(syncFnName) { } // create asynchronous versions of callsArg* and yields* methods -forEach(Object.keys(proto), function (method) { +forEach(Object.keys(proto), function(method) { // need to avoid creating anotherasync versions of the newly added async methods if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) { proto[method + "Async"] = createAsyncVersion(method); @@ -222,7 +222,7 @@ forEach(Object.keys(proto), function (method) { }); function createBehavior(behaviorMethod) { - return function () { + return function() { this.defaultBehavior = this.defaultBehavior || proto.create(this); this.defaultBehavior[behaviorMethod].apply(this.defaultBehavior, arguments); return this; @@ -230,7 +230,7 @@ function createBehavior(behaviorMethod) { } function addBehavior(stub, name, fn) { - proto[name] = function () { + proto[name] = function() { fn.apply(this, concat([this], slice(arguments))); return this.stub || this; }; diff --git a/lib/sinon/blob.js b/lib/sinon/blob.js index 8f386d231..e9b2345ac 100644 --- a/lib/sinon/blob.js +++ b/lib/sinon/blob.js @@ -1,10 +1,10 @@ /*global Blob */ "use strict"; -exports.isSupported = (function () { +exports.isSupported = (function() { try { return Boolean(new Blob()); } catch (e) { return false; } -}()); +})(); diff --git a/lib/sinon/call.js b/lib/sinon/call.js index 97435612c..d1088adf8 100644 --- a/lib/sinon/call.js +++ b/lib/sinon/call.js @@ -38,9 +38,13 @@ var callProto = { return false; } - return reduce(calledWithArgs, function (prev, arg, i) { - return prev && deepEqual(arg, self.args[i]); - }, true); + return reduce( + calledWithArgs, + function(prev, arg, i) { + return prev && deepEqual(arg, self.args[i]); + }, + true + ); }, calledWithMatch: function calledWithMatch() { @@ -51,16 +55,19 @@ var callProto = { return false; } - return reduce(calledWithMatchArgs, function (prev, expectation, i) { - var actual = self.args[i]; + return reduce( + calledWithMatchArgs, + function(prev, expectation, i) { + var actual = self.args[i]; - return prev && (sinonMatch && sinonMatch(expectation).test(actual)); - }, true); + return prev && (sinonMatch && sinonMatch(expectation).test(actual)); + }, + true + ); }, calledWithExactly: function calledWithExactly() { - return arguments.length === this.args.length && - this.calledWith.apply(this, arguments); + return arguments.length === this.args.length && this.calledWith.apply(this, arguments); }, notCalledWith: function notCalledWith() { @@ -87,61 +94,57 @@ var callProto = { return this.proxy.prototype && this.thisValue instanceof this.proxy; }, - calledBefore: function (other) { + calledBefore: function(other) { return this.callId < other.callId; }, - calledAfter: function (other) { + calledAfter: function(other) { return this.callId > other.callId; }, - calledImmediatelyBefore: function (other) { + calledImmediatelyBefore: function(other) { return this.callId === other.callId - 1; }, - calledImmediatelyAfter: function (other) { + calledImmediatelyAfter: function(other) { return this.callId === other.callId + 1; }, - callArg: function (pos) { + callArg: function(pos) { this.ensureArgIsAFunction(pos); return this.args[pos](); }, - callArgOn: function (pos, thisValue) { + callArgOn: function(pos, thisValue) { this.ensureArgIsAFunction(pos); return this.args[pos].apply(thisValue); }, - callArgWith: function (pos) { + callArgWith: function(pos) { return this.callArgOnWith.apply(this, concat([pos, null], slice(arguments, 1))); }, - callArgOnWith: function (pos, thisValue) { + callArgOnWith: function(pos, thisValue) { this.ensureArgIsAFunction(pos); var args = slice(arguments, 2); return this.args[pos].apply(thisValue, args); }, - throwArg: function (pos) { + throwArg: function(pos) { if (pos > this.args.length) { - throw new TypeError( - "Not enough arguments: " + pos - + " required but only " + this.args.length - + " present" - ); + throw new TypeError("Not enough arguments: " + pos + " required but only " + this.args.length + " present"); } throw this.args[pos]; }, - yield: function () { + yield: function() { return this.yieldOn.apply(this, concat([null], slice(arguments, 0))); }, - yieldOn: function (thisValue) { + yieldOn: function(thisValue) { var args = slice(this.args); - var yieldFn = filter(args, function (arg) { + var yieldFn = filter(args, function(arg) { return typeof arg === "function"; })[0]; @@ -152,26 +155,29 @@ var callProto = { return yieldFn.apply(thisValue, slice(arguments, 1)); }, - yieldTo: function (prop) { + yieldTo: function(prop) { return this.yieldToOn.apply(this, concat([prop, null], slice(arguments, 1))); }, - yieldToOn: function (prop, thisValue) { + yieldToOn: function(prop, thisValue) { var args = slice(this.args); - var yieldArg = filter(args, function (arg) { + var yieldArg = filter(args, function(arg) { return arg && typeof arg[prop] === "function"; })[0]; var yieldFn = yieldArg && yieldArg[prop]; if (!yieldFn) { - throwYieldError(this.proxy, " cannot yield to '" + valueToString(prop) + - "' since no callback was passed.", args); + throwYieldError( + this.proxy, + " cannot yield to '" + valueToString(prop) + "' since no callback was passed.", + args + ); } return yieldFn.apply(thisValue, slice(arguments, 2)); }, - toString: function () { + toString: function() { var callStr = this.proxy ? String(this.proxy) + "(" : ""; var formattedArgs; @@ -179,7 +185,7 @@ var callProto = { return ":("; } - formattedArgs = map(this.args, function (arg) { + formattedArgs = map(this.args, function(arg) { return sinonFormat(arg); }); @@ -198,18 +204,16 @@ var callProto = { } if (this.stack) { // Omit the error message and the two top stack frames in sinon itself: - callStr += ( this.stack.split("\n")[3] || "unknown" ).replace(/^\s*(?:at\s+|@)?/, " at "); + callStr += (this.stack.split("\n")[3] || "unknown").replace(/^\s*(?:at\s+|@)?/, " at "); } return callStr; }, - ensureArgIsAFunction: function (pos) { + ensureArgIsAFunction: function(pos) { if (typeof this.args[pos] !== "function") { throw new TypeError( - "Expected argument at position " + pos - + " to be a Function, but was " - + typeof this.args[pos] + "Expected argument at position " + pos + " to be a Function, but was " + typeof this.args[pos] ); } } @@ -217,8 +221,8 @@ var callProto = { Object.defineProperty(callProto, "stack", { enumerable: true, configurable: true, - get: function () { - return this.errorWithCallStack && this.errorWithCallStack.stack || ""; + get: function() { + return (this.errorWithCallStack && this.errorWithCallStack.stack) || ""; } }); @@ -230,7 +234,7 @@ function createSpyCall(spy, thisValue, args, returnValue, exception, id, errorWi } var proxyCall = Object.create(callProto); - var lastArg = args.length > 0 && args[args.length - 1] || undefined; + var lastArg = (args.length > 0 && args[args.length - 1]) || undefined; var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined; proxyCall.proxy = spy; diff --git a/lib/sinon/collect-own-methods.js b/lib/sinon/collect-own-methods.js index dafbb6973..35c0eb680 100644 --- a/lib/sinon/collect-own-methods.js +++ b/lib/sinon/collect-own-methods.js @@ -6,10 +6,7 @@ var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnPropert var push = require("@sinonjs/commons").prototypes.array.push; function collectMethod(methods, object, prop, propOwner) { - if ( - typeof getPropertyDescriptor(propOwner, prop).value === "function" && - hasOwnProperty(object, prop) - ) { + if (typeof getPropertyDescriptor(propOwner, prop).value === "function" && hasOwnProperty(object, prop)) { push(methods, object[prop]); } } diff --git a/lib/sinon/color.js b/lib/sinon/color.js index d14ad9cfb..cf5875638 100644 --- a/lib/sinon/color.js +++ b/lib/sinon/color.js @@ -10,22 +10,22 @@ function colorize(str, color) { return "\x1b[" + color + "m" + str + "\x1b[0m"; } -exports.red = function (str) { +exports.red = function(str) { return colorize(str, 31); }; -exports.green = function (str) { +exports.green = function(str) { return colorize(str, 32); }; -exports.cyan = function (str) { +exports.cyan = function(str) { return colorize(str, 96); }; -exports.white = function (str) { +exports.white = function(str) { return colorize(str, 39); }; -exports.bold = function (str) { +exports.bold = function(str) { return colorize(str, 1); }; diff --git a/lib/sinon/create-sandbox.js b/lib/sinon/create-sandbox.js index aa637f8df..4bcd1053c 100644 --- a/lib/sinon/create-sandbox.js +++ b/lib/sinon/create-sandbox.js @@ -53,8 +53,8 @@ function createSandbox(config) { var exposed = configuredSandbox.inject({}); if (config.properties) { - forEach(config.properties, function (prop) { - var value = exposed[prop] || prop === "sandbox" && configuredSandbox; + forEach(config.properties, function(prop) { + var value = exposed[prop] || (prop === "sandbox" && configuredSandbox); exposeValue(configuredSandbox, config, prop, value); }); } else { diff --git a/lib/sinon/default-behaviors.js b/lib/sinon/default-behaviors.js index bdab9a0de..30e1f8add 100644 --- a/lib/sinon/default-behaviors.js +++ b/lib/sinon/default-behaviors.js @@ -13,13 +13,13 @@ function throwsException(fake, error, message) { if (typeof error === "function") { fake.exceptionCreator = error; } else if (typeof error === "string") { - fake.exceptionCreator = function () { + fake.exceptionCreator = function() { var newException = new Error(message || ""); newException.name = error; return newException; }; } else if (!error) { - fake.exceptionCreator = function () { + fake.exceptionCreator = function() { return new Error("Error"); }; } else { @@ -84,7 +84,7 @@ module.exports = { fake.promiseLibrary = promiseLibrary; }, - yields: function (fake) { + yields: function(fake) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice(arguments, 1); fake.callbackContext = undefined; @@ -92,7 +92,7 @@ module.exports = { fake.callbackAsync = false; }, - yieldsRight: function (fake) { + yieldsRight: function(fake) { fake.callArgAt = useRightMostCallback; fake.callbackArguments = slice(arguments, 1); fake.callbackContext = undefined; @@ -100,7 +100,7 @@ module.exports = { fake.callbackAsync = false; }, - yieldsOn: function (fake, context) { + yieldsOn: function(fake, context) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice(arguments, 2); fake.callbackContext = context; @@ -108,7 +108,7 @@ module.exports = { fake.callbackAsync = false; }, - yieldsTo: function (fake, prop) { + yieldsTo: function(fake, prop) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice(arguments, 2); fake.callbackContext = undefined; @@ -116,7 +116,7 @@ module.exports = { fake.callbackAsync = false; }, - yieldsToOn: function (fake, prop, context) { + yieldsToOn: function(fake, prop, context) { fake.callArgAt = useLeftMostCallback; fake.callbackArguments = slice(arguments, 3); fake.callbackContext = context; @@ -234,10 +234,15 @@ module.exports = { set: function set(fake, setterFunction) { var rootStub = fake.stub || fake; - Object.defineProperty(rootStub.rootObj, rootStub.propName, { // eslint-disable-line accessor-pairs - set: setterFunction, - configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName) - }); + Object.defineProperty( + rootStub.rootObj, + rootStub.propName, + // eslint-disable-next-line accessor-pairs + { + set: setterFunction, + configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName) + } + ); return fake; }, @@ -256,7 +261,7 @@ module.exports = { }; function createAsyncVersion(syncFnName) { - return function () { + return function() { var result = module.exports[syncFnName].apply(this, arguments); this.callbackAsync = true; return result; @@ -264,7 +269,7 @@ function createAsyncVersion(syncFnName) { } // create asynchronous versions of callsArg* and yields* methods -forEach(Object.keys(module.exports), function (method) { +forEach(Object.keys(module.exports), function(method) { // need to avoid creating anotherasync versions of the newly added async methods if (method.match(/^(callsArg|yields)/) && !method.match(/Async/)) { module.exports[method + "Async"] = createAsyncVersion(method); diff --git a/lib/sinon/fake.js b/lib/sinon/fake.js index c2bcfda0e..d016d777e 100644 --- a/lib/sinon/fake.js +++ b/lib/sinon/fake.js @@ -27,7 +27,7 @@ function cleanProxy(f) { "yieldToOn" ]; - forEach(undesirableProperties, function (key) { + forEach(undesirableProperties, function(key) { delete f[key]; }); @@ -36,8 +36,8 @@ function cleanProxy(f) { var uuid = 0; function wrapFunc(f) { - var fakeInstance = function () { - var lastArg = arguments.length > 0 && arguments[arguments.length - 1] || undefined; + var fakeInstance = function() { + var lastArg = (arguments.length > 0 && arguments[arguments.length - 1]) || undefined; var callback = lastArg && typeof lastArg === "function" ? lastArg : undefined; /* eslint-disable no-use-before-define */ @@ -102,7 +102,7 @@ function yieldInternal(async, values) { throw new TypeError("Expected last argument to be a function"); } if (async) { - nextTick(function () { + nextTick(function() { callback.apply(null, values); }); } else { diff --git a/lib/sinon/match.js b/lib/sinon/match.js index dfaf2ea74..43e3aa9de 100644 --- a/lib/sinon/match.js +++ b/lib/sinon/match.js @@ -25,8 +25,7 @@ var stringIndexOf = stringProto.indexOf; function assertType(value, type, name) { var actual = typeOf(value); if (actual !== type) { - throw new TypeError("Expected type of " + name + " to be " + - type + ", but was " + actual); + throw new TypeError("Expected type of " + name + " to be " + type + ", but was " + actual); } } @@ -37,7 +36,7 @@ function assertMethodExists(value, method, name, methodPath) { } var matcher = { - toString: function () { + toString: function() { return this.message; } }; @@ -51,7 +50,7 @@ function matchObject(expectation, actual) { return false; } - return arrayEvery(Object.keys(expectation), function (key) { + return arrayEvery(Object.keys(expectation), function(key) { var exp = expectation[key]; var act = actual[key]; @@ -72,48 +71,48 @@ function matchObject(expectation, actual) { } var TYPE_MAP = { - function: function (m, expectation, message) { + function: function(m, expectation, message) { m.test = expectation; m.message = message || "match(" + functionName(expectation) + ")"; }, - number: function (m, expectation) { - m.test = function (actual) { + number: function(m, expectation) { + m.test = function(actual) { // we need type coercion here return expectation == actual; // eslint-disable-line eqeqeq }; }, - object: function (m, expectation) { + object: function(m, expectation) { var array = []; if (typeof expectation.test === "function") { - m.test = function (actual) { + m.test = function(actual) { return expectation.test(actual) === true; }; m.message = "match(" + functionName(expectation.test) + ")"; return m; } - array = map(Object.keys(expectation), function (key) { + array = map(Object.keys(expectation), function(key) { return key + ": " + valueToString(expectation[key]); }); - m.test = function (actual) { + m.test = function(actual) { return matchObject(expectation, actual); }; m.message = "match(" + join(array, ", ") + ")"; return m; }, - regexp: function (m, expectation) { - m.test = function (actual) { + regexp: function(m, expectation) { + m.test = function(actual) { return typeof actual === "string" && expectation.test(actual); }; }, - string: function (m, expectation) { - m.test = function (actual) { + string: function(m, expectation) { + m.test = function(actual) { return typeof actual === "string" && stringIndexOf(actual, expectation) !== -1; }; - m.message = "match(\"" + expectation + "\")"; + m.message = 'match("' + expectation + '")'; } }; @@ -124,7 +123,7 @@ function match(expectation, message) { if (type in TYPE_MAP) { TYPE_MAP[type](m, expectation, message); } else { - m.test = function (actual) { + m.test = function(actual) { return deepEqual(expectation, actual); }; } @@ -136,7 +135,7 @@ function match(expectation, message) { return m; } -matcher.or = function (m2) { +matcher.or = function(m2) { var matcher2 = m2; if (!arguments.length) { throw new TypeError("Matcher expected"); @@ -145,14 +144,14 @@ matcher.or = function (m2) { } var m1 = this; var or = Object.create(matcher); - or.test = function (actual) { + or.test = function(actual) { return m1.test(actual) || matcher2.test(actual); }; or.message = m1.message + ".or(" + matcher2.message + ")"; return or; }; -matcher.and = function (m2) { +matcher.and = function(m2) { var matcher2 = m2; if (!arguments.length) { throw new TypeError("Matcher expected"); @@ -161,7 +160,7 @@ matcher.and = function (m2) { } var m1 = this; var and = Object.create(matcher); - and.test = function (actual) { + and.test = function(actual) { return m1.test(actual) && matcher2.test(actual); }; and.message = m1.message + ".and(" + matcher2.message + ")"; @@ -170,70 +169,69 @@ matcher.and = function (m2) { match.isMatcher = isMatcher; -match.any = match(function () { +match.any = match(function() { return true; }, "any"); -match.defined = match(function (actual) { +match.defined = match(function(actual) { return actual !== null && actual !== undefined; }, "defined"); -match.truthy = match(function (actual) { +match.truthy = match(function(actual) { return Boolean(actual); }, "truthy"); -match.falsy = match(function (actual) { +match.falsy = match(function(actual) { return !actual; }, "falsy"); -match.same = function (expectation) { - return match(function (actual) { +match.same = function(expectation) { + return match(function(actual) { return expectation === actual; }, "same(" + valueToString(expectation) + ")"); }; -match.in = function (arrayOfExpectations) { +match.in = function(arrayOfExpectations) { if (!Array.isArray(arrayOfExpectations)) { throw new TypeError("array expected"); } - return match(function (actual) { - return some(arrayOfExpectations, function (expectation) { + return match(function(actual) { + return some(arrayOfExpectations, function(expectation) { return expectation === actual; }); }, "in(" + valueToString(arrayOfExpectations) + ")"); }; -match.typeOf = function (type) { +match.typeOf = function(type) { assertType(type, "string", "type"); - return match(function (actual) { + return match(function(actual) { return typeOf(actual) === type; - }, "typeOf(\"" + type + "\")"); + }, 'typeOf("' + type + '")'); }; -match.instanceOf = function (type) { +match.instanceOf = function(type) { if (typeof Symbol === "undefined" || typeof Symbol.hasInstance === "undefined") { assertType(type, "function", "type"); } else { assertMethodExists(type, Symbol.hasInstance, "type", "[Symbol.hasInstance]"); } - return match(function (actual) { + return match(function(actual) { return actual instanceof type; }, "instanceOf(" + (functionName(type) || Object.prototype.toString.call(type)) + ")"); }; function createPropertyMatcher(propertyTest, messagePrefix) { - return function (property, value) { + return function(property, value) { assertType(property, "string", "property"); var onlyProperty = arguments.length === 1; - var message = messagePrefix + "(\"" + property + "\""; + var message = messagePrefix + '("' + property + '"'; if (!onlyProperty) { message += ", " + valueToString(value); } message += ")"; - return match(function (actual) { - if (actual === undefined || actual === null || - !propertyTest(actual, property)) { + return match(function(actual) { + if (actual === undefined || actual === null || !propertyTest(actual, property)) { return false; } return onlyProperty || deepEqual(value, actual[property]); @@ -241,146 +239,180 @@ function createPropertyMatcher(propertyTest, messagePrefix) { }; } -match.has = createPropertyMatcher(function (actual, property) { +match.has = createPropertyMatcher(function(actual, property) { if (typeof actual === "object") { return property in actual; } return actual[property] !== undefined; }, "has"); -match.hasOwn = createPropertyMatcher(function (actual, property) { +match.hasOwn = createPropertyMatcher(function(actual, property) { return hasOwnProperty(actual, property); }, "hasOwn"); -match.hasNested = function (property, value) { +match.hasNested = function(property, value) { assertType(property, "string", "property"); var onlyProperty = arguments.length === 1; - var message = "hasNested(\"" + property + "\""; + var message = 'hasNested("' + property + '"'; if (!onlyProperty) { message += ", " + valueToString(value); } message += ")"; - return match(function (actual) { - if (actual === undefined || actual === null || - get(actual, property) === undefined) { + return match(function(actual) { + if (actual === undefined || actual === null || get(actual, property) === undefined) { return false; } return onlyProperty || deepEqual(value, get(actual, property)); }, message); }; -match.every = function (predicate) { +match.every = function(predicate) { if (!isMatcher(predicate)) { throw new TypeError("Matcher expected"); } - return match(function (actual) { + return match(function(actual) { if (typeOf(actual) === "object") { - return every(Object.keys(actual), function (key) { + return every(Object.keys(actual), function(key) { return predicate.test(actual[key]); }); } - return Boolean(actual) && typeOf(actual.forEach) === "function" && every(actual, function (element) { - return predicate.test(element); - }); + return ( + Boolean(actual) && + typeOf(actual.forEach) === "function" && + every(actual, function(element) { + return predicate.test(element); + }) + ); }, "every(" + predicate.message + ")"); }; -match.some = function (predicate) { +match.some = function(predicate) { if (!isMatcher(predicate)) { throw new TypeError("Matcher expected"); } - return match(function (actual) { + return match(function(actual) { if (typeOf(actual) === "object") { - return !every(Object.keys(actual), function (key) { + return !every(Object.keys(actual), function(key) { return !predicate.test(actual[key]); }); } - return Boolean(actual) && typeOf(actual.forEach) === "function" && !every(actual, function (element) { - return !predicate.test(element); - }); + return ( + Boolean(actual) && + typeOf(actual.forEach) === "function" && + !every(actual, function(element) { + return !predicate.test(element); + }) + ); }, "some(" + predicate.message + ")"); }; match.array = match.typeOf("array"); -match.array.deepEquals = function (expectation) { - return match(function (actual) { +match.array.deepEquals = function(expectation) { + return match(function(actual) { // Comparing lengths is the fastest way to spot a difference before iterating through every item var sameLength = actual.length === expectation.length; - return typeOf(actual) === "array" && sameLength && every(actual, function (element, index) { - return expectation[index] === element; - }); + return ( + typeOf(actual) === "array" && + sameLength && + every(actual, function(element, index) { + return expectation[index] === element; + }) + ); }, "deepEquals([" + iterableToString(expectation) + "])"); }; -match.array.startsWith = function (expectation) { - return match(function (actual) { - return typeOf(actual) === "array" && every(expectation, function (expectedElement, index) { - return actual[index] === expectedElement; - }); +match.array.startsWith = function(expectation) { + return match(function(actual) { + return ( + typeOf(actual) === "array" && + every(expectation, function(expectedElement, index) { + return actual[index] === expectedElement; + }) + ); }, "startsWith([" + iterableToString(expectation) + "])"); }; -match.array.endsWith = function (expectation) { - return match(function (actual) { +match.array.endsWith = function(expectation) { + return match(function(actual) { // This indicates the index in which we should start matching var offset = actual.length - expectation.length; - return typeOf(actual) === "array" && every(expectation, function (expectedElement, index) { - return actual[offset + index] === expectedElement; - }); + return ( + typeOf(actual) === "array" && + every(expectation, function(expectedElement, index) { + return actual[offset + index] === expectedElement; + }) + ); }, "endsWith([" + iterableToString(expectation) + "])"); }; -match.array.contains = function (expectation) { - return match(function (actual) { - return typeOf(actual) === "array" && every(expectation, function (expectedElement) { - return arrayIndexOf(actual, expectedElement) !== -1; - }); +match.array.contains = function(expectation) { + return match(function(actual) { + return ( + typeOf(actual) === "array" && + every(expectation, function(expectedElement) { + return arrayIndexOf(actual, expectedElement) !== -1; + }) + ); }, "contains([" + iterableToString(expectation) + "])"); }; match.map = match.typeOf("map"); match.map.deepEquals = function mapDeepEquals(expectation) { - return match(function (actual) { + return match(function(actual) { // Comparing lengths is the fastest way to spot a difference before iterating through every item var sameLength = actual.size === expectation.size; - return typeOf(actual) === "map" && sameLength && every(actual, function (element, key) { - return expectation.has(key) && expectation.get(key) === element; - }); + return ( + typeOf(actual) === "map" && + sameLength && + every(actual, function(element, key) { + return expectation.has(key) && expectation.get(key) === element; + }) + ); }, "deepEquals(Map[" + iterableToString(expectation) + "])"); }; match.map.contains = function mapContains(expectation) { - return match(function (actual) { - return typeOf(actual) === "map" && every(expectation, function (element, key) { - return actual.has(key) && actual.get(key) === element; - }); + return match(function(actual) { + return ( + typeOf(actual) === "map" && + every(expectation, function(element, key) { + return actual.has(key) && actual.get(key) === element; + }) + ); }, "contains(Map[" + iterableToString(expectation) + "])"); }; match.set = match.typeOf("set"); match.set.deepEquals = function setDeepEquals(expectation) { - return match(function (actual) { + return match(function(actual) { // Comparing lengths is the fastest way to spot a difference before iterating through every item var sameLength = actual.size === expectation.size; - return typeOf(actual) === "set" && sameLength && every(actual, function (element) { - return expectation.has(element); - }); + return ( + typeOf(actual) === "set" && + sameLength && + every(actual, function(element) { + return expectation.has(element); + }) + ); }, "deepEquals(Set[" + iterableToString(expectation) + "])"); }; match.set.contains = function setContains(expectation) { - return match(function (actual) { - return typeOf(actual) === "set" && every(expectation, function (element) { - return actual.has(element); - }); + return match(function(actual) { + return ( + typeOf(actual) === "set" && + every(expectation, function(element) { + return actual.has(element); + }) + ); }, "contains(Set[" + iterableToString(expectation) + "])"); }; diff --git a/lib/sinon/mock-expectation.js b/lib/sinon/mock-expectation.js index 61fab1a32..aa168b97d 100644 --- a/lib/sinon/mock-expectation.js +++ b/lib/sinon/mock-expectation.js @@ -62,7 +62,7 @@ function receivedMaxCalls(expectation) { function verifyMatcher(possibleMatcher, arg) { var isMatcher = match && match.isMatcher(possibleMatcher); - return isMatcher && possibleMatcher.test(arg) || true; + return (isMatcher && possibleMatcher.test(arg)) || true; } var mockExpectation = { @@ -151,8 +151,13 @@ var mockExpectation = { } if ("expectedThis" in this && this.expectedThis !== thisValue) { - mockExpectation.fail(this.method + " called with " + valueToString(thisValue) + - " as thisValue, expected " + valueToString(this.expectedThis)); + mockExpectation.fail( + this.method + + " called with " + + valueToString(thisValue) + + " as thisValue, expected " + + valueToString(this.expectedThis) + ); } if (!("expectedArguments" in this)) { @@ -160,32 +165,54 @@ var mockExpectation = { } if (!args) { - mockExpectation.fail(this.method + " received no arguments, expected " + - format(expectedArguments)); + mockExpectation.fail(this.method + " received no arguments, expected " + format(expectedArguments)); } if (args.length < expectedArguments.length) { - mockExpectation.fail(this.method + " received too few arguments (" + format(args) + - "), expected " + format(expectedArguments)); + mockExpectation.fail( + this.method + + " received too few arguments (" + + format(args) + + "), expected " + + format(expectedArguments) + ); } - if (this.expectsExactArgCount && - args.length !== expectedArguments.length) { - mockExpectation.fail(this.method + " received too many arguments (" + format(args) + - "), expected " + format(expectedArguments)); + if (this.expectsExactArgCount && args.length !== expectedArguments.length) { + mockExpectation.fail( + this.method + + " received too many arguments (" + + format(args) + + "), expected " + + format(expectedArguments) + ); } - forEach(expectedArguments, function (expectedArgument, i) { - if (!verifyMatcher(expectedArgument, args[i])) { - mockExpectation.fail(this.method + " received wrong arguments " + format(args) + - ", didn't match " + String(expectedArguments)); - } - - if (!deepEqual(expectedArgument, args[i])) { - mockExpectation.fail(this.method + " received wrong arguments " + format(args) + - ", expected " + format(expectedArguments)); - } - }, this); + forEach( + expectedArguments, + function(expectedArgument, i) { + if (!verifyMatcher(expectedArgument, args[i])) { + mockExpectation.fail( + this.method + + " received wrong arguments " + + format(args) + + ", didn't match " + + String(expectedArguments) + ); + } + + if (!deepEqual(expectedArgument, args[i])) { + mockExpectation.fail( + this.method + + " received wrong arguments " + + format(args) + + ", expected " + + format(expectedArguments) + ); + } + }, + this + ); }, allowsCall: function allowsCall(thisValue, args) { @@ -210,12 +237,11 @@ var mockExpectation = { return false; } - if (this.expectsExactArgCount && - _args.length !== expectedArguments.length) { + if (this.expectsExactArgCount && _args.length !== expectedArguments.length) { return false; } - return every(expectedArguments, function (expectedArgument, i) { + return every(expectedArguments, function(expectedArgument, i) { if (!verifyMatcher(expectedArgument, _args[i])) { return false; } @@ -244,7 +270,7 @@ var mockExpectation = { return this; }, - toString: function () { + toString: function() { var args = slice(this.expectedArguments || []); if (!this.expectsExactArgCount) { @@ -256,15 +282,13 @@ var mockExpectation = { args: args }); - var message = callStr.replace(", [...", "[, ...") + " " + - expectedCallCountInWords(this); + var message = callStr.replace(", [...", "[, ...") + " " + expectedCallCountInWords(this); if (this.met()) { return "Expectation met: " + message; } - return "Expected " + message + " (" + - callCountInWords(this.callCount) + ")"; + return "Expected " + message + " (" + callCountInWords(this.callCount) + ")"; }, verify: function verify() { diff --git a/lib/sinon/mock.js b/lib/sinon/mock.js index a242cfbd3..5164ec832 100644 --- a/lib/sinon/mock.js +++ b/lib/sinon/mock.js @@ -33,13 +33,12 @@ function each(collection, callback) { } function arrayEquals(arr1, arr2, compareLength) { - if (compareLength && (arr1.length !== arr2.length)) { + if (compareLength && arr1.length !== arr2.length) { return false; } - return every(arr1, function (element, i) { + return every(arr1, function(element, i) { return deepEqual(element, arr2[i]); - }); } @@ -71,7 +70,7 @@ extend(mock, { this.expectations[method] = []; var mockObject = this; - wrapMethod(this.object, method, function () { + wrapMethod(this.object, method, function() { return mockObject.invokeMethod(method, this, arguments); }); @@ -89,7 +88,7 @@ extend(mock, { restore: function restore() { var object = this.object; - each(this.proxies, function (proxy) { + each(this.proxies, function(proxy) { if (typeof object[proxy].restore === "function") { object[proxy].restore(); } @@ -101,8 +100,8 @@ extend(mock, { var messages = this.failures ? slice(this.failures) : []; var met = []; - each(this.proxies, function (proxy) { - each(expectations[proxy], function (expectation) { + each(this.proxies, function(proxy) { + each(expectations[proxy], function(expectation) { if (!expectation.met()) { push(messages, String(expectation)); } else { @@ -135,13 +134,13 @@ extend(mock, { var currentArgs = args || []; var available; - var expectationsWithMatchingArgs = filter(expectations, function (expectation) { + var expectationsWithMatchingArgs = filter(expectations, function(expectation) { var expectedArgs = expectation.expectedArguments || []; return arrayEquals(expectedArgs, currentArgs, expectation.expectsExactArgCount); }); - var expectationsToApply = filter(expectationsWithMatchingArgs, function (expectation) { + var expectationsToApply = filter(expectationsWithMatchingArgs, function(expectation) { return !expectation.met() && expectation.allowsCall(thisValue, args); }); @@ -152,7 +151,7 @@ extend(mock, { var messages = []; var exhausted = 0; - forEach(expectationsWithMatchingArgs, function (expectation) { + forEach(expectationsWithMatchingArgs, function(expectation) { if (expectation.allowsCall(thisValue, args)) { available = available || expectation; } else { @@ -164,27 +163,37 @@ extend(mock, { return available.apply(thisValue, args); } - forEach(expectations, function (expectation) { + forEach(expectations, function(expectation) { push(messages, " " + String(expectation)); }); - unshift(messages, "Unexpected call: " + spyCallToString.call({ - proxy: method, - args: args - })); + unshift( + messages, + "Unexpected call: " + + spyCallToString.call({ + proxy: method, + args: args + }) + ); var err = new Error(); if (!err.stack) { // PhantomJS does not serialize the stack trace until the error has been thrown try { throw err; - } catch (e) {/* empty */} + } catch (e) { + /* empty */ + } } - push(this.failures, "Unexpected call: " + spyCallToString.call({ - proxy: method, - args: args, - stack: err.stack - })); + push( + this.failures, + "Unexpected call: " + + spyCallToString.call({ + proxy: method, + args: args, + stack: err.stack + }) + ); mockExpectation.fail(join(messages, "\n")); } diff --git a/lib/sinon/sandbox.js b/lib/sinon/sandbox.js index c4f03e2bd..2334fca10 100644 --- a/lib/sinon/sandbox.js +++ b/lib/sinon/sandbox.js @@ -24,11 +24,11 @@ var push = arrayProto.push; var reverse = arrayProto.reverse; function applyOnEach(fakes, method) { - var matchingFakes = filter(fakes, function (fake) { + var matchingFakes = filter(fakes, function(fake) { return typeof fake[method] === "function"; }); - forEach(matchingFakes, function (fake) { + forEach(matchingFakes, function(fake) { fake[method](); }); } @@ -47,7 +47,7 @@ function Sandbox() { }; // this is for testing only - sandbox.getRestorers = function () { + sandbox.getRestorers = function() { return fakeRestorers; }; @@ -59,15 +59,15 @@ function Sandbox() { }; sandbox.inject = function inject(obj) { - obj.spy = function () { + obj.spy = function() { return sandbox.spy.apply(null, arguments); }; - obj.stub = function () { + obj.stub = function() { return sandbox.stub.apply(null, arguments); }; - obj.mock = function () { + obj.mock = function() { return sandbox.mock.apply(null, arguments); }; @@ -111,7 +111,7 @@ function Sandbox() { } } - forEach(collection, function (fake) { + forEach(collection, function(fake) { if (typeof fake === "function") { privateResetHistory(fake); return; @@ -139,7 +139,7 @@ function Sandbox() { applyOnEach(collection, "restore"); collection = []; - forEach(fakeRestorers, function (restorer) { + forEach(fakeRestorers, function(restorer) { restorer(); }); fakeRestorers = []; @@ -155,7 +155,7 @@ function Sandbox() { return; } - forEach(injectedKeys, function (injectedKey) { + forEach(injectedKeys, function(injectedKey) { delete injectInto[injectedKey]; }); @@ -174,7 +174,7 @@ function Sandbox() { } function verifyNotReplaced(object, property) { - forEach(fakeRestorers, function (fakeRestorer) { + forEach(fakeRestorers, function(fakeRestorer) { if (fakeRestorer.object === object && fakeRestorer.property === property) { throw new TypeError("Attempted to replace " + property + " which is already replaced"); } @@ -294,7 +294,7 @@ function Sandbox() { if (isStubbingEntireObject) { var ownMethods = collectOwnMethods(stubbed); - forEach(ownMethods, function (method) { + forEach(ownMethods, function(method) { push(collection, method); }); @@ -307,7 +307,8 @@ function Sandbox() { return stubbed; }; - sandbox.fake = function fake(f) { // eslint-disable-line no-unused-vars + // eslint-disable-next-line no-unused-vars + sandbox.fake = function fake(f) { var s = sinonFake.apply(sinonFake, arguments); push(collection, s); @@ -315,10 +316,10 @@ function Sandbox() { return s; }; - forEach(Object.keys(sinonFake), function (key) { + forEach(Object.keys(sinonFake), function(key) { var fakeBehavior = sinonFake[key]; if (typeof fakeBehavior === "function") { - sandbox.fake[key] = function () { + sandbox.fake[key] = function() { var s = fakeBehavior.apply(fakeBehavior, arguments); push(collection, s); diff --git a/lib/sinon/spy-formatters.js b/lib/sinon/spy-formatters.js index 3e0d6d903..d79919fe8 100644 --- a/lib/sinon/spy-formatters.js +++ b/lib/sinon/spy-formatters.js @@ -23,7 +23,7 @@ function colorSinonMatchText(matcher, calledArg, calledArgMessage) { } function colorDiffText(diff) { - var objects = map(diff, function (part) { + var objects = map(diff, function(part) { var text = part.value; if (part.added) { text = color.green(text); @@ -39,16 +39,16 @@ function colorDiffText(diff) { } module.exports = { - c: function (spyInstance) { + c: function(spyInstance) { return timesInWords(spyInstance.callCount); }, - n: function (spyInstance) { + n: function(spyInstance) { // eslint-disable-next-line local-rules/no-prototype-methods return spyInstance.toString(); }, - D: function (spyInstance, args) { + D: function(spyInstance, args) { var message = ""; for (var i = 0, l = spyInstance.callCount; i < l; ++i) { @@ -73,7 +73,7 @@ module.exports = { return message; }, - C: function (spyInstance) { + C: function(spyInstance) { var calls = []; for (var i = 0, l = spyInstance.callCount; i < l; ++i) { @@ -88,7 +88,7 @@ module.exports = { return calls.length > 0 ? "\n" + join(calls, "\n") : ""; }, - t: function (spyInstance) { + t: function(spyInstance) { var objects = []; for (var i = 0, l = spyInstance.callCount; i < l; ++i) { @@ -98,7 +98,12 @@ module.exports = { return join(objects, ", "); }, - "*": function (spyInstance, args) { - return join(map(args, function (arg) { return sinonFormat(arg); }), ", "); + "*": function(spyInstance, args) { + return join( + map(args, function(arg) { + return sinonFormat(arg); + }), + ", " + ); } }; diff --git a/lib/sinon/spy.js b/lib/sinon/spy.js index 207dd2af4..9edbc5e30 100644 --- a/lib/sinon/spy.js +++ b/lib/sinon/spy.js @@ -38,7 +38,7 @@ function spy(object, property, types) { } if (!object && !property) { - return spy.create(function () { + return spy.create(function() { return; }); } @@ -50,7 +50,7 @@ function spy(object, property, types) { descriptor = {}; methodDesc = getPropertyDescriptor(object, property); - forEach(types, function (type) { + forEach(types, function(type) { descriptor[type] = spy.create(methodDesc[type]); }); @@ -81,19 +81,71 @@ function createProxy(func, proxyLength) { // ref: https://github.com/sinonjs/sinon/issues/710 switch (proxyLength) { /*eslint-disable no-unused-vars, max-len*/ - case 1: p = function proxy(a) { return p.invoke(func, this, slice(arguments)); }; break; - case 2: p = function proxy(a, b) { return p.invoke(func, this, slice(arguments)); }; break; - case 3: p = function proxy(a, b, c) { return p.invoke(func, this, slice(arguments)); }; break; - case 4: p = function proxy(a, b, c, d) { return p.invoke(func, this, slice(arguments)); }; break; - case 5: p = function proxy(a, b, c, d, e) { return p.invoke(func, this, slice(arguments)); }; break; - case 6: p = function proxy(a, b, c, d, e, f) { return p.invoke(func, this, slice(arguments)); }; break; - case 7: p = function proxy(a, b, c, d, e, f, g) { return p.invoke(func, this, slice(arguments)); }; break; - case 8: p = function proxy(a, b, c, d, e, f, g, h) { return p.invoke(func, this, slice(arguments)); }; break; - case 9: p = function proxy(a, b, c, d, e, f, g, h, i) { return p.invoke(func, this, slice(arguments)); }; break; - case 10: p = function proxy(a, b, c, d, e, f, g, h, i, j) { return p.invoke(func, this, slice(arguments)); }; break; - case 11: p = function proxy(a, b, c, d, e, f, g, h, i, j, k) { return p.invoke(func, this, slice(arguments)); }; break; - case 12: p = function proxy(a, b, c, d, e, f, g, h, i, j, k, l) { return p.invoke(func, this, slice(arguments)); }; break; - default: p = function proxy() { return p.invoke(func, this, slice(arguments)); }; break; + case 1: + p = function proxy(a) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 2: + p = function proxy(a, b) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 3: + p = function proxy(a, b, c) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 4: + p = function proxy(a, b, c, d) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 5: + p = function proxy(a, b, c, d, e) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 6: + p = function proxy(a, b, c, d, e, f) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 7: + p = function proxy(a, b, c, d, e, f, g) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 8: + p = function proxy(a, b, c, d, e, f, g, h) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 9: + p = function proxy(a, b, c, d, e, f, g, h, i) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 10: + p = function proxy(a, b, c, d, e, f, g, h, i, j) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 11: + p = function proxy(a, b, c, d, e, f, g, h, i, j, k) { + return p.invoke(func, this, slice(arguments)); + }; + break; + case 12: + p = function proxy(a, b, c, d, e, f, g, h, i, j, k, l) { + return p.invoke(func, this, slice(arguments)); + }; + break; + default: + p = function proxy() { + return p.invoke(func, this, slice(arguments)); + }; + break; /*eslint-enable*/ } } else { @@ -111,10 +163,12 @@ var uuid = 0; var spyApi = { formatters: require("./spy-formatters"), - resetHistory: function () { + resetHistory: function() { if (this.invoking) { - var err = new Error("Cannot reset Sinon function while invoking it. " + - "Move the call to .resetHistory outside of the callback."); + var err = new Error( + "Cannot reset Sinon function while invoking it. " + + "Move the call to .resetHistory outside of the callback." + ); err.name = "InvalidResetException"; throw err; } @@ -136,7 +190,7 @@ var spyApi = { this.callIds = []; this.errorsWithCallStack = []; if (this.fakes) { - forEach(this.fakes, function (fake) { + forEach(this.fakes, function(fake) { if (fake.resetHistory) { fake.resetHistory(); } else { @@ -152,9 +206,8 @@ var spyApi = { var name; var funk = func; - if (typeof funk !== "function") { - funk = function () { + funk = function() { return; }; } else { @@ -187,7 +240,7 @@ var spyApi = { push(this.thisValues, thisValue); push(this.args, args); push(this.callIds, currentCallId); - forEach(matchings, function (matching) { + forEach(matchings, function(matching) { incrementCallCount.call(matching); push(matching.thisValues, thisValue); push(matching.args, args); @@ -196,7 +249,7 @@ var spyApi = { // Make call properties available from within the spied function: createCallProperties.call(this); - forEach(matchings, function (matching) { + forEach(matchings, function(matching) { createCallProperties.call(matching); }); @@ -223,7 +276,7 @@ var spyApi = { push(this.exceptions, exception); push(this.returnValues, returnValue); - forEach(matchings, function (matching) { + forEach(matchings, function(matching) { push(matching.exceptions, exception); push(matching.returnValues, returnValue); }); @@ -234,15 +287,17 @@ var spyApi = { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack try { throw err; - } catch (e) {/* empty */} + } catch (e) { + /* empty */ + } push(this.errorsWithCallStack, err); - forEach(matchings, function (matching) { + forEach(matchings, function(matching) { push(matching.errorsWithCallStack, err); }); // Make return value and exception available in the calls: createCallProperties.call(this); - forEach(matchings, function (matching) { + forEach(matchings, function(matching) { createCallProperties.call(matching); }); @@ -263,12 +318,18 @@ var spyApi = { return null; } - return spyCall(this, this.thisValues[i], this.args[i], - this.returnValues[i], this.exceptions[i], - this.callIds[i], this.errorsWithCallStack[i]); + return spyCall( + this, + this.thisValues[i], + this.args[i], + this.returnValues[i], + this.exceptions[i], + this.callIds[i], + this.errorsWithCallStack[i] + ); }, - getCalls: function () { + getCalls: function() { var calls = []; var i; @@ -315,7 +376,7 @@ var spyApi = { return this.callIds[this.callCount - 1] === spyFn.callIds[spyFn.callCount - 1] + 1; }, - withArgs: function () { + withArgs: function() { var args = slice(arguments); if (this.fakes) { @@ -339,11 +400,11 @@ var spyApi = { fake.defaultBehavior.promiseLibrary = original.defaultBehavior.promiseLibrary; } - fake.withArgs = function () { + fake.withArgs = function() { return original.withArgs.apply(original, arguments); }; - forEach(original.args, function (arg, i) { + forEach(original.args, function(arg, i) { if (!fake.matches(arg)) { return; } @@ -361,29 +422,28 @@ var spyApi = { return fake; }, - matchingFakes: function (args, strict) { - return filter.call(this.fakes || [], function (fake) { + matchingFakes: function(args, strict) { + return filter.call(this.fakes || [], function(fake) { return fake.matches(args, strict); }); }, - matches: function (args, strict) { + matches: function(args, strict) { var margs = this.matchingArguments; - if (margs.length <= args.length && - deepEqual(margs, slice(args, 0, margs.length))) { + if (margs.length <= args.length && deepEqual(margs, slice(args, 0, margs.length))) { return !strict || margs.length === args.length; } return undefined; }, - printf: function (format) { + printf: function(format) { var spyInstance = this; var args = slice(arguments, 1); var formatter; - return (format || "").replace(/%(.)/g, function (match, specifyer) { + return (format || "").replace(/%(.)/g, function(match, specifyer) { formatter = spyApi.formatters[specifyer]; if (typeof formatter === "function") { @@ -398,7 +458,7 @@ var spyApi = { }; function delegateToCalls(method, matchAny, actual, returnsValues, notCalled, totalCallCount) { - spyApi[method] = function () { + spyApi[method] = function() { if (!this.called) { if (notCalled) { return notCalled.apply(this, arguments); @@ -444,10 +504,10 @@ delegateToCalls("alwaysCalledWithMatch", false, "calledWithMatch"); delegateToCalls("calledWithExactly", true); delegateToCalls("calledOnceWithExactly", true, "calledWithExactly", false, undefined, 1); delegateToCalls("alwaysCalledWithExactly", false, "calledWithExactly"); -delegateToCalls("neverCalledWith", false, "notCalledWith", false, function () { +delegateToCalls("neverCalledWith", false, "notCalledWith", false, function() { return true; }); -delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", false, function () { +delegateToCalls("neverCalledWithMatch", false, "notCalledWithMatch", false, function() { return true; }); delegateToCalls("threw", true); @@ -457,32 +517,34 @@ delegateToCalls("alwaysReturned", false, "returned"); delegateToCalls("calledWithNew", true); delegateToCalls("alwaysCalledWithNew", false, "calledWithNew"); /* eslint-disable local-rules/no-prototype-methods */ -delegateToCalls("callArg", false, "callArgWith", true, function () { +delegateToCalls("callArg", false, "callArgWith", true, function() { throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); }); spyApi.callArgWith = spyApi.callArg; -delegateToCalls("callArgOn", false, "callArgOnWith", true, function () { +delegateToCalls("callArgOn", false, "callArgOnWith", true, function() { throw new Error(this.toString() + " cannot call arg since it was not yet invoked."); }); spyApi.callArgOnWith = spyApi.callArgOn; -delegateToCalls("throwArg", false, "throwArg", false, function () { +delegateToCalls("throwArg", false, "throwArg", false, function() { throw new Error(this.toString() + " cannot throw arg since it was not yet invoked."); }); -delegateToCalls("yield", false, "yield", true, function () { +delegateToCalls("yield", false, "yield", true, function() { throw new Error(this.toString() + " cannot yield since it was not yet invoked."); }); // "invokeCallback" is an alias for "yield" since "yield" is invalid in strict mode. spyApi.invokeCallback = spyApi.yield; -delegateToCalls("yieldOn", false, "yieldOn", true, function () { +delegateToCalls("yieldOn", false, "yieldOn", true, function() { throw new Error(this.toString() + " cannot yield since it was not yet invoked."); }); -delegateToCalls("yieldTo", false, "yieldTo", true, function (property) { - throw new Error(this.toString() + " cannot yield to '" + valueToString(property) + - "' since it was not yet invoked."); +delegateToCalls("yieldTo", false, "yieldTo", true, function(property) { + throw new Error( + this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked." + ); }); -delegateToCalls("yieldToOn", false, "yieldToOn", true, function (property) { - throw new Error(this.toString() + " cannot yield to '" + valueToString(property) + - "' since it was not yet invoked."); +delegateToCalls("yieldToOn", false, "yieldToOn", true, function(property) { + throw new Error( + this.toString() + " cannot yield to '" + valueToString(property) + "' since it was not yet invoked." + ); }); /* eslint-enable local-rules/no-prototype-methods */ diff --git a/lib/sinon/stub-entire-object.js b/lib/sinon/stub-entire-object.js index 0babce6d6..5b76ae7cd 100644 --- a/lib/sinon/stub-entire-object.js +++ b/lib/sinon/stub-entire-object.js @@ -4,7 +4,7 @@ var getPropertyDescriptor = require("./util/core/get-property-descriptor"); var walk = require("./util/core/walk"); function stubEntireObject(stub, object) { - walk(object || {}, function (prop, propOwner) { + walk(object || {}, function(prop, propOwner) { // we don't want to stub things like toString(), valueOf(), etc. so we only stub if the object // is not Object.prototype if ( diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index a8ee147bd..d84241bcb 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -38,14 +38,15 @@ function stub(object, property) { var actualDescriptor = getPropertyDescriptor(object, property); var isStubbingEntireObject = typeof property === "undefined" && typeof object === "object"; var isCreatingNewStub = !object && typeof property === "undefined"; - var isStubbingNonFuncProperty = (typeof object === "object" || typeof object === "function") - && typeof property !== "undefined" - && (typeof actualDescriptor === "undefined" - || typeof actualDescriptor.value !== "function") - && typeof descriptor === "undefined"; - var isStubbingExistingMethod = typeof object === "object" - && typeof actualDescriptor !== "undefined" - && typeof actualDescriptor.value === "function"; + var isStubbingNonFuncProperty = + (typeof object === "object" || typeof object === "function") && + typeof property !== "undefined" && + (typeof actualDescriptor === "undefined" || typeof actualDescriptor.value !== "function") && + typeof descriptor === "undefined"; + var isStubbingExistingMethod = + typeof object === "object" && + typeof actualDescriptor !== "undefined" && + typeof actualDescriptor.value === "function"; var arity = isStubbingExistingMethod ? object[property].length : 0; if (isStubbingEntireObject) { @@ -71,24 +72,22 @@ function stub(object, property) { return isStubbingNonFuncProperty ? s : wrapMethod(object, property, s); } -stub.createStubInstance = function (constructor, overrides) { +stub.createStubInstance = function(constructor, overrides) { if (typeof constructor !== "function") { throw new TypeError("The constructor should be a function."); } var stubbedObject = stub(Object.create(constructor.prototype)); - forEach(Object.keys(overrides || {}), function (propertyName) { + forEach(Object.keys(overrides || {}), function(propertyName) { if (propertyName in stubbedObject) { var value = overrides[propertyName]; if (value.createStubInstance) { stubbedObject[propertyName] = value; - } - else { + } else { stubbedObject[propertyName].returns(value); } - } - else { + } else { throw new Error("Cannot stub " + propertyName + ". Property does not exist!"); } }); @@ -97,13 +96,11 @@ stub.createStubInstance = function (constructor, overrides) { /*eslint-disable no-use-before-define*/ function getParentBehaviour(stubInstance) { - return (stubInstance.parent && getCurrentBehavior(stubInstance.parent)); + return stubInstance.parent && getCurrentBehavior(stubInstance.parent); } function getDefaultBehavior(stubInstance) { - return stubInstance.defaultBehavior || - getParentBehaviour(stubInstance) || - behavior.create(stubInstance); + return stubInstance.defaultBehavior || getParentBehaviour(stubInstance) || behavior.create(stubInstance); } function getCurrentBehavior(stubInstance) { @@ -116,13 +113,16 @@ var uuid = 0; var proto = { create: function create(stubLength) { - var functionStub = function () { + var functionStub = function() { var args = slice(arguments); var matchings = functionStub.matchingFakes(args); - var fnStub = pop(sort(matchings, function (a, b) { - return a.matchingArguments.length - b.matchingArguments.length; - })) || functionStub; + var fnStub = + pop( + sort(matchings, function(a, b) { + return a.matchingArguments.length - b.matchingArguments.length; + }) + ) || functionStub; return getCurrentBehavior(fnStub).invoke(this, arguments); }; @@ -142,7 +142,7 @@ var proto = { return functionStub; }, - resetBehavior: function () { + resetBehavior: function() { var fakes = this.fakes || []; this.defaultBehavior = null; @@ -156,14 +156,14 @@ var proto = { this.returnThis = false; this.resolveThis = false; - forEach(fakes, function (fake) { + forEach(fakes, function(fake) { fake.resetBehavior(); }); }, resetHistory: spy.resetHistory, - reset: function () { + reset: function() { this.resetHistory(); this.resetBehavior(); }, @@ -189,17 +189,19 @@ var proto = { } }; -forEach(Object.keys(behavior), function (method) { - if (hasOwnProperty(behavior, method) && +forEach(Object.keys(behavior), function(method) { + if ( + hasOwnProperty(behavior, method) && !hasOwnProperty(proto, method) && method !== "create" && method !== "withArgs" && - method !== "invoke") { + method !== "invoke" + ) { proto[method] = behavior.createBehavior(method); } }); -forEach(Object.keys(behaviors), function (method) { +forEach(Object.keys(behaviors), function(method) { if (hasOwnProperty(behaviors, method) && !hasOwnProperty(proto, method)) { behavior.addBehavior(stub, method, behaviors[method]); } diff --git a/lib/sinon/util/core/deep-equal.js b/lib/sinon/util/core/deep-equal.js index b87df09d7..1922d5759 100644 --- a/lib/sinon/util/core/deep-equal.js +++ b/lib/sinon/util/core/deep-equal.js @@ -13,13 +13,13 @@ function isReallyNaN(val) { return val !== val; } -var deepEqual = module.exports = function deepEqual(a, b, matcher) { +var deepEqual = (module.exports = function deepEqual(a, b, matcher) { if (a === null && b === null) { return true; } if (typeof a !== "object" || typeof b !== "object") { - return isReallyNaN(a) && isReallyNaN(b) || a === b; + return (isReallyNaN(a) && isReallyNaN(b)) || a === b; } if (a instanceof Error && b instanceof Error) { @@ -40,7 +40,7 @@ var deepEqual = module.exports = function deepEqual(a, b, matcher) { if (matcher) { var keys = Object.keys(a); - var allKeysMatch = every(keys, function (key) { + var allKeysMatch = every(keys, function(key) { return matcher(a[key], b[key]); }); @@ -48,9 +48,9 @@ var deepEqual = module.exports = function deepEqual(a, b, matcher) { } return false; -}; +}); -deepEqual.use = function (match) { +deepEqual.use = function(match) { return function deepEqual$matcher(a, b) { // If both are matchers they must be the same instance in order to be considered equal // If we didn't do that we would end up running one matcher against the other @@ -61,7 +61,6 @@ deepEqual.use = function (match) { return a.test(b); } - return deepEqual(a, b, deepEqual$matcher); }; }; diff --git a/lib/sinon/util/core/deprecated.js b/lib/sinon/util/core/deprecated.js index 885798cc8..af1ef93bf 100644 --- a/lib/sinon/util/core/deprecated.js +++ b/lib/sinon/util/core/deprecated.js @@ -3,8 +3,8 @@ // wrap returns a function that will invoke the supplied function and print a deprecation warning to the console each // time it is called. -exports.wrap = function (func, msg) { - var wrapped = function () { +exports.wrap = function(func, msg) { + var wrapped = function() { exports.printWarning(msg); return func.apply(this, arguments); }; @@ -17,11 +17,11 @@ exports.wrap = function (func, msg) { // defaultMsg returns a string which can be supplied to `wrap()` to notify the user that a particular part of the // sinon API has been deprecated. /* istanbul ignore next */ -exports.defaultMsg = function (funcName) { +exports.defaultMsg = function(funcName) { return "sinon." + funcName + " is deprecated and will be removed from the public API in a future version of sinon."; }; -exports.printWarning = function (msg) { +exports.printWarning = function(msg) { // Watch out for IE7 and below! :( if (typeof console !== "undefined") { /* istanbul ignore else */ diff --git a/lib/sinon/util/core/every.js b/lib/sinon/util/core/every.js index ecfe02ea4..f4614ef08 100644 --- a/lib/sinon/util/core/every.js +++ b/lib/sinon/util/core/every.js @@ -6,7 +6,7 @@ module.exports = function every(obj, fn) { try { /* eslint-disable-next-line local-rules/no-prototype-methods */ - obj.forEach(function () { + obj.forEach(function() { if (!fn.apply(this, arguments)) { // Throwing an error is the only way to break `forEach` throw new Error(); diff --git a/lib/sinon/util/core/extend.js b/lib/sinon/util/core/extend.js index cac6451b0..b400786b8 100644 --- a/lib/sinon/util/core/extend.js +++ b/lib/sinon/util/core/extend.js @@ -8,36 +8,36 @@ var push = arrayProto.push; var slice = arrayProto.slice; // Adapted from https://developer.mozilla.org/en/docs/ECMAScript_DontEnum_attribute#JScript_DontEnum_Bug -var hasDontEnumBug = (function () { +var hasDontEnumBug = (function() { var obj = { - constructor: function () { + constructor: function() { return "0"; }, - toString: function () { + toString: function() { return "1"; }, - valueOf: function () { + valueOf: function() { return "2"; }, - toLocaleString: function () { + toLocaleString: function() { return "3"; }, - prototype: function () { + prototype: function() { return "4"; }, - isPrototypeOf: function () { + isPrototypeOf: function() { return "5"; }, - propertyIsEnumerable: function () { + propertyIsEnumerable: function() { return "6"; }, - hasOwnProperty: function () { + hasOwnProperty: function() { return "7"; }, - length: function () { + length: function() { return "8"; }, - unique: function () { + unique: function() { return "9"; } }; @@ -49,7 +49,7 @@ var hasDontEnumBug = (function () { } } return join(result, "") !== "0123456789"; -}()); +})(); /* Public: Extend target in place with all (own) properties from sources in-order. Thus, last source will * override properties in previous sources. diff --git a/lib/sinon/util/core/format.js b/lib/sinon/util/core/format.js index e1bc96661..c81950c5b 100644 --- a/lib/sinon/util/core/format.js +++ b/lib/sinon/util/core/format.js @@ -17,7 +17,7 @@ function format() { return formatter.ascii.apply(formatter, arguments); } -format.setFormatter = function (aCustomFormatter) { +format.setFormatter = function(aCustomFormatter) { if (typeof aCustomFormatter !== "function") { throw new Error("format.setFormatter must be called with a function"); } diff --git a/lib/sinon/util/core/is-es-module.js b/lib/sinon/util/core/is-es-module.js index 157b9f79c..1d83dfa03 100644 --- a/lib/sinon/util/core/is-es-module.js +++ b/lib/sinon/util/core/is-es-module.js @@ -11,11 +11,8 @@ * * @returns {Boolean} true when the object is a module */ -module.exports = function (object) { +module.exports = function(object) { return ( - object && - typeof Symbol !== "undefined" && - object[Symbol.toStringTag] === "Module" && - Object.isSealed(object) + object && typeof Symbol !== "undefined" && object[Symbol.toStringTag] === "Module" && Object.isSealed(object) ); }; diff --git a/lib/sinon/util/core/iterable-to-string.js b/lib/sinon/util/core/iterable-to-string.js index 57c436419..2bf2357af 100644 --- a/lib/sinon/util/core/iterable-to-string.js +++ b/lib/sinon/util/core/iterable-to-string.js @@ -12,7 +12,7 @@ module.exports = function iterableToString(obj) { function mapToString(map) { /* eslint-disable-next-line local-rules/no-prototype-methods */ - map.forEach(function (value, key) { + map.forEach(function(value, key) { representation += "[" + stringify(key) + "," + stringify(value) + "],"; }); @@ -22,7 +22,7 @@ module.exports = function iterableToString(obj) { function genericIterableToString(iterable) { /* eslint-disable-next-line local-rules/no-prototype-methods */ - iterable.forEach(function (value) { + iterable.forEach(function(value) { representation += stringify(value) + ","; }); diff --git a/lib/sinon/util/core/order-by-first-call.js b/lib/sinon/util/core/order-by-first-call.js index ffec59af4..92da964bc 100644 --- a/lib/sinon/util/core/order-by-first-call.js +++ b/lib/sinon/util/core/order-by-first-call.js @@ -3,12 +3,12 @@ var sort = require("@sinonjs/commons").prototypes.array.sort; module.exports = function orderByFirstCall(spies) { - return sort(spies, function (a, b) { + return sort(spies, function(a, b) { // uuid, won't ever be equal var aCall = a.getCall(0); var bCall = b.getCall(0); - var aId = aCall && aCall.callId || -1; - var bId = bCall && bCall.callId || -1; + var aId = (aCall && aCall.callId) || -1; + var bId = (bCall && bCall.callId) || -1; return aId < bId ? -1 : 1; }); diff --git a/lib/sinon/util/core/restore.js b/lib/sinon/util/core/restore.js index 4ea4a73ed..0a1a5a136 100644 --- a/lib/sinon/util/core/restore.js +++ b/lib/sinon/util/core/restore.js @@ -5,7 +5,7 @@ var walk = require("./walk"); module.exports = function restore(object) { if (object !== null && typeof object === "object") { - walk(object, function (prop) { + walk(object, function(prop) { if (isRestorable(object[prop])) { object[prop].restore(); } diff --git a/lib/sinon/util/core/walk.js b/lib/sinon/util/core/walk.js index eb57cc7ac..42abebc14 100644 --- a/lib/sinon/util/core/walk.js +++ b/lib/sinon/util/core/walk.js @@ -16,11 +16,10 @@ function walkInternal(obj, iterator, context, originalObj, seen) { return; } - forEach(Object.getOwnPropertyNames(obj), function (k) { + forEach(Object.getOwnPropertyNames(obj), function(k) { if (seen[k] !== true) { seen[k] = true; - var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ? - originalObj : obj; + var target = typeof Object.getOwnPropertyDescriptor(obj, k).get === "function" ? originalObj : obj; iterator.call(context, k, target); } }); diff --git a/lib/sinon/util/core/wrap-method.js b/lib/sinon/util/core/wrap-method.js index 55ea77001..1fb8e7faf 100644 --- a/lib/sinon/util/core/wrap-method.js +++ b/lib/sinon/util/core/wrap-method.js @@ -32,8 +32,9 @@ module.exports = function wrapMethod(object, property, method) { var error; if (!isFunction(wrappedMethod)) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - valueToString(property) + " as function"); + error = new TypeError( + "Attempted to wrap " + typeof wrappedMethod + " property " + valueToString(property) + " as function" + ); } else if (wrappedMethod.restore && wrappedMethod.restore.sinon) { error = new TypeError("Attempted to wrap " + valueToString(property) + " which is already wrapped"); } else if (wrappedMethod.calledBefore) { @@ -63,12 +64,13 @@ module.exports = function wrapMethod(object, property, method) { var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwnProperty(object, property); if (hasES5Support) { - var methodDesc = (typeof method === "function") ? {value: method} : method; + var methodDesc = typeof method === "function" ? { value: method } : method; wrappedMethodDesc = getPropertyDescriptor(object, property); if (!wrappedMethodDesc) { - error = new TypeError("Attempted to wrap " + (typeof wrappedMethod) + " property " + - property + " as function"); + error = new TypeError( + "Attempted to wrap " + typeof wrappedMethod + " property " + property + " as function" + ); } else if (wrappedMethodDesc.restore && wrappedMethodDesc.restore.sinon) { error = new TypeError("Attempted to wrap " + property + " which is already wrapped"); } @@ -93,7 +95,7 @@ module.exports = function wrapMethod(object, property, method) { // catch failing assignment // this is the converse of the check in `.restore` below - if ( typeof method === "function" && object[property] !== method ) { + if (typeof method === "function" && object[property] !== method) { // correct any wrongdoings caused by the defineProperty call above, // such as adding new items (if object was a Storage object) delete object[property]; @@ -107,9 +109,9 @@ module.exports = function wrapMethod(object, property, method) { // Set up an Error object for a stack trace which can be used later to find what line of // code the original method was created on. - method.stackTraceError = (new Error("Stack Trace for original")); + method.stackTraceError = new Error("Stack Trace for original"); - method.restore = function () { + method.restore = function() { // For prototype properties try to reset by delete first. // If this fails (ex: localStorage on mobile safari) then force a reset // via direct assignment. @@ -129,10 +131,9 @@ module.exports = function wrapMethod(object, property, method) { if (descriptor && descriptor.value === method) { object[property] = wrappedMethod; } - } - else { - // Use strict equality comparison to check failures then force a reset - // via direct assignment. + } else { + // Use strict equality comparison to check failures then force a reset + // via direct assignment. if (object[property] === method) { object[property] = wrappedMethod; } diff --git a/lib/sinon/util/fake_timers.js b/lib/sinon/util/fake_timers.js index 7be8e273f..07ea77b56 100644 --- a/lib/sinon/util/fake_timers.js +++ b/lib/sinon/util/fake_timers.js @@ -7,7 +7,7 @@ var llx = require("lolex"); * @param {number|Date|Object} args The unix epoch value to install with (default 0) * @returns {Object} Returns a lolex clock instance */ -exports.useFakeTimers = function (args) { +exports.useFakeTimers = function(args) { var config = {}; if (typeof args === "undefined" || args === null) { @@ -31,7 +31,7 @@ exports.useFakeTimers = function (args) { }; exports.clock = { - create: function (now) { + create: function(now) { return llx.createClock(now); } }; @@ -39,8 +39,8 @@ exports.clock = { exports.timers = { setTimeout: setTimeout, clearTimeout: clearTimeout, - setImmediate: (typeof setImmediate !== "undefined" ? setImmediate : undefined), - clearImmediate: (typeof clearImmediate !== "undefined" ? clearImmediate : undefined), + setImmediate: typeof setImmediate !== "undefined" ? setImmediate : undefined, + clearImmediate: typeof clearImmediate !== "undefined" ? clearImmediate : undefined, setInterval: setInterval, clearInterval: clearInterval, Date: Date diff --git a/test/assert-test.js b/test/assert-test.js index 38dc0ff1b..623de5e4f 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -10,56 +10,62 @@ var assert = referee.assert; var refute = referee.refute; function requiresValidFake(method) { - it("should fail with non-function fake", function () { - assert.exception(function () { + it("should fail with non-function fake", function() { + assert.exception(function() { sinonAssert[method]({}); }); }); } -describe("assert", function () { - beforeEach(function () { +describe("assert", function() { + beforeEach(function() { this.global = typeof window !== "undefined" ? window : global; - this.setUpStubs = function () { + this.setUpStubs = function() { this.stub = sinonStub.create(); sinonStub(sinonAssert, "fail").throws(); sinonStub(sinonAssert, "pass"); }; - this.tearDownStubs = function () { + this.tearDownStubs = function() { sinonAssert.fail.restore(); sinonAssert.pass.restore(); }; }); - it("is object", function () { + it("is object", function() { assert.isObject(sinonAssert); }); - it("supports proxy property", function () { - var api = { method: function () { return; } }; - api.method.proxy = function () { return; }; + it("supports proxy property", function() { + var api = { + method: function() { + return; + } + }; + api.method.proxy = function() { + return; + }; sinonSpy(api, "method"); api.method(); - refute.exception(function () { + refute.exception(function() { sinonAssert.calledOnce(api.method); }); }); - describe(".fail", function () { - beforeEach(function () { + describe(".fail", function() { + beforeEach(function() { this.exceptionName = sinonAssert.failException; }); - afterEach(function () { + afterEach(function() { sinonAssert.failException = this.exceptionName; }); - it("throws exception", function () { + it("throws exception", function() { assert.exception( - function () { + function() { sinonAssert.fail("Some message"); }, { @@ -68,93 +74,98 @@ describe("assert", function () { ); }); - it("throws configured exception type", function () { + it("throws configured exception type", function() { sinonAssert.failException = "CustomError"; - assert.exception(function () { - sinonAssert.fail("Some message"); - }, {name: "CustomError"}); + assert.exception( + function() { + sinonAssert.fail("Some message"); + }, + { name: "CustomError" } + ); }); }); - describe("with stubs", function () { - beforeEach(function () { + describe("with stubs", function() { + beforeEach(function() { this.setUpStubs(); }); - afterEach(function () { + afterEach(function() { this.tearDownStubs(); }); - describe(".match", function () { - it("fails when arguments to not match", function () { - assert.exception(function () { + describe(".match", function() { + it("fails when arguments to not match", function() { + assert.exception(function() { sinonAssert.match("foo", "bar"); }); assert(sinonAssert.fail.calledOnce); }); - it("passes when argumens match", function () { + it("passes when argumens match", function() { sinonAssert.match("foo", "foo"); assert(sinonAssert.pass.calledOnce); }); }); - describe(".called", function () { + describe(".called", function() { requiresValidFake("called"); - it("fails when method does not exist", function () { - assert.exception(function () { + it("fails when method does not exist", function() { + assert.exception(function() { sinonAssert.called(); }); assert(sinonAssert.fail.called); }); - it("fails when method is not stub", function () { - assert.exception(function () { - sinonAssert.called(function () { return; }); + it("fails when method is not stub", function() { + assert.exception(function() { + sinonAssert.called(function() { + return; + }); }); assert(sinonAssert.fail.called); }); - it("fails when method was not called", function () { + it("fails when method was not called", function() { var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.called(stub); }); assert(sinonAssert.fail.called); }); - it("fails when called with more than one argument", function () { + it("fails when called with more than one argument", function() { var stub = this.stub; stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.called(stub, 1); }); }); - it("does not fail when method was called", function () { + it("does not fail when method was called", function() { var stub = this.stub; stub(); - refute.exception(function () { + refute.exception(function() { sinonAssert.called(stub); }); assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var stub = this.stub; stub(); - refute.exception(function () { + refute.exception(function() { sinonAssert.called(stub); }); @@ -163,55 +174,57 @@ describe("assert", function () { }); }); - describe(".notCalled", function () { + describe(".notCalled", function() { requiresValidFake("notCalled"); - it("fails when method does not exist", function () { - assert.exception(function () { + it("fails when method does not exist", function() { + assert.exception(function() { sinonAssert.notCalled(); }); assert(sinonAssert.fail.called); }); - it("fails when method is not stub", function () { - assert.exception(function () { - sinonAssert.notCalled(function () { return; }); + it("fails when method is not stub", function() { + assert.exception(function() { + sinonAssert.notCalled(function() { + return; + }); }); assert(sinonAssert.fail.called); }); - it("fails when method was called", function () { + it("fails when method was called", function() { var stub = this.stub; stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.notCalled(stub); }); assert(sinonAssert.fail.called); }); - it("fails when called with more than one argument", function () { + it("fails when called with more than one argument", function() { var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.notCalled(stub, 1); }); }); - it("passes when method was not called", function () { + it("passes when method was not called", function() { var stub = this.stub; - refute.exception(function () { + refute.exception(function() { sinonAssert.notCalled(stub); }); assert.isFalse(sinonAssert.fail.called); }); - it("should call pass callback", function () { + it("should call pass callback", function() { var stub = this.stub; sinonAssert.notCalled(stub); @@ -220,69 +233,70 @@ describe("assert", function () { }); }); - describe(".calledOnce", function () { + describe(".calledOnce", function() { requiresValidFake("calledOnce"); - - it("fails when method does not exist", function () { - assert.exception(function () { + it("fails when method does not exist", function() { + assert.exception(function() { sinonAssert.calledOnce(); }); assert(sinonAssert.fail.called); }); - it("fails when method is not stub", function () { - assert.exception(function () { - sinonAssert.calledOnce(function () { return; }); + it("fails when method is not stub", function() { + assert.exception(function() { + sinonAssert.calledOnce(function() { + return; + }); }); assert(sinonAssert.fail.called); }); - it("fails when method was not called", function () { + it("fails when method was not called", function() { var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.calledOnce(stub); }); assert(sinonAssert.fail.called); }); - it("fails when called with more than one argument", function () { + it("fails when called with more than one argument", function() { var stub = this.stub; stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledOnce(stub, 1); }); }); - it("passes when method was called", function () { + it("passes when method was called", function() { var stub = this.stub; stub(); - refute.exception(function () { + refute.exception(function() { sinonAssert.calledOnce(stub); }); assert.isFalse(sinonAssert.fail.called); }); - it("fails when method was called more than once", function () { + it("fails when method was called more than once", function() { var stub = this.stub; stub(); stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledOnce(stub); }); assert(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var stub = this.stub; stub(); sinonAssert.calledOnce(stub); @@ -292,39 +306,39 @@ describe("assert", function () { }); }); - describe(".calledTwice", function () { + describe(".calledTwice", function() { requiresValidFake("calledTwice"); - it("fails if called once", function () { + it("fails if called once", function() { var stub = this.stub; this.stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledTwice(stub); }); }); - it("fails when called with more than one argument", function () { + it("fails when called with more than one argument", function() { var stub = this.stub; this.stub(); this.stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledTwice(stub, 1); }); }); - it("passes if called twice", function () { + it("passes if called twice", function() { var stub = this.stub; this.stub(); this.stub(); - refute.exception(function () { + refute.exception(function() { sinonAssert.calledTwice(stub); }); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var stub = this.stub; stub(); stub(); @@ -335,41 +349,41 @@ describe("assert", function () { }); }); - describe(".calledThrice", function () { + describe(".calledThrice", function() { requiresValidFake("calledThrice"); - it("fails if called once", function () { + it("fails if called once", function() { var stub = this.stub; this.stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledThrice(stub); }); }); - it("fails when called with more than one argument", function () { + it("fails when called with more than one argument", function() { var stub = this.stub; this.stub(); this.stub(); this.stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledThrice(stub, 1); }); }); - it("passes if called thrice", function () { + it("passes if called thrice", function() { var stub = this.stub; this.stub(); this.stub(); this.stub(); - refute.exception(function () { + refute.exception(function() { sinonAssert.calledThrice(stub); }); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var stub = this.stub; stub(); stub(); @@ -381,32 +395,32 @@ describe("assert", function () { }); }); - describe(".callOrder", function () { - it("passes when calls were done in right order", function () { + describe(".callOrder", function() { + it("passes when calls were done in right order", function() { var spy1 = sinonSpy(); var spy2 = sinonSpy(); spy1(); spy2(); - refute.exception(function () { + refute.exception(function() { sinonAssert.callOrder(spy1, spy2); }); }); - it("fails when calls were done in wrong order", function () { + it("fails when calls were done in wrong order", function() { var spy1 = sinonSpy(); var spy2 = sinonSpy(); spy2(); spy1(); - assert.exception(function () { + assert.exception(function() { sinonAssert.callOrder(spy1, spy2); }); assert(sinonAssert.fail.called); }); - it("passes when many calls were done in right order", function () { + it("passes when many calls were done in right order", function() { var spy1 = sinonSpy(); var spy2 = sinonSpy(); var spy3 = sinonSpy(); @@ -416,12 +430,12 @@ describe("assert", function () { spy3(); spy4(); - refute.exception(function () { + refute.exception(function() { sinonAssert.callOrder(spy1, spy2, spy3, spy4); }); }); - it("fails when one of many calls were done in wrong order", function () { + it("fails when one of many calls were done in wrong order", function() { var spy1 = sinonSpy(); var spy2 = sinonSpy(); var spy3 = sinonSpy(); @@ -431,14 +445,14 @@ describe("assert", function () { spy4(); spy3(); - assert.exception(function () { + assert.exception(function() { sinonAssert.callOrder(spy1, spy2, spy3, spy4); }); assert(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var stubs = [sinonSpy(), sinonSpy()]; stubs[0](); stubs[1](); @@ -448,7 +462,7 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("callOrder")); }); - it("passes for multiple calls to same spy", function () { + it("passes for multiple calls to same spy", function() { var first = sinonSpy(); var second = sinonSpy(); @@ -456,40 +470,40 @@ describe("assert", function () { second(); first(); - refute.exception(function () { + refute.exception(function() { sinonAssert.callOrder(first, second, first); }); }); - it("fails if first spy was not called", function () { + it("fails if first spy was not called", function() { var first = sinonSpy(); var second = sinonSpy(); second(); - assert.exception(function () { + assert.exception(function() { sinonAssert.callOrder(first, second); }); }); - it("fails if second spy was not called", function () { + it("fails if second spy was not called", function() { var first = sinonSpy(); var second = sinonSpy(); first(); - assert.exception(function () { + assert.exception(function() { sinonAssert.callOrder(first, second); }); }); }); - describe(".calledOn", function () { - it("fails when method does not exist", function () { + describe(".calledOn", function() { + it("fails when method does not exist", function() { var object = {}; sinonStub(this.stub, "calledOn"); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledOn(null, object); }); @@ -497,31 +511,33 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("fails when method is not stub", function () { + it("fails when method is not stub", function() { var object = {}; sinonStub(this.stub, "calledOn"); - assert.exception(function () { - sinonAssert.calledOn(function () { return; }, object); + assert.exception(function() { + sinonAssert.calledOn(function() { + return; + }, object); }); assert.isFalse(this.stub.calledOn.calledWith(object)); assert(sinonAssert.fail.called); }); - it("fails when method fails", function () { + it("fails when method fails", function() { var object = {}; sinonStub(this.stub, "calledOn").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.calledOn(stub, object); }); assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { var object = {}; sinonStub(this.stub, "calledOn").returns(true); var stub = this.stub; @@ -531,7 +547,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var obj = {}; this.stub.call(obj); sinonAssert.calledOn(this.stub, obj); @@ -540,7 +556,7 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledOn")); }); - it("works with spyCall", function () { + it("works with spyCall", function() { var spy = sinonSpy(); var target = {}; spy(); @@ -551,13 +567,13 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledOn")); }); - it("fails when spyCall failed", function () { + it("fails when spyCall failed", function() { var spy = sinonSpy(); var target = {}; spy(); spy.call(target); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledOn(spy.lastCall, 1); }); @@ -565,13 +581,13 @@ describe("assert", function () { }); }); - describe(".calledWithNew", function () { + describe(".calledWithNew", function() { requiresValidFake("calledWithNew"); - it("fails when method does not exist", function () { + it("fails when method does not exist", function() { sinonStub(this.stub, "calledWithNew"); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWithNew(null); }); @@ -579,29 +595,31 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("fails when method is not stub", function () { + it("fails when method is not stub", function() { sinonStub(this.stub, "calledWithNew"); - assert.exception(function () { - sinonAssert.calledWithNew(function () { return; }); + assert.exception(function() { + sinonAssert.calledWithNew(function() { + return; + }); }); assert.isFalse(this.stub.calledWithNew.called); assert(sinonAssert.fail.called); }); - it("fails when method fails", function () { + it("fails when method fails", function() { sinonStub(this.stub, "calledWithNew").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWithNew(stub); }); assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { sinonStub(this.stub, "calledWithNew").returns(true); var stub = this.stub; @@ -610,7 +628,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { new this.stub(); // eslint-disable-line no-new, new-cap sinonAssert.calledWithNew(this.stub); @@ -618,7 +636,7 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledWithNew")); }); - it("works with spyCall", function () { + it("works with spyCall", function() { var spy = sinonSpy(); spy(); new spy(); // eslint-disable-line no-new, new-cap @@ -628,12 +646,12 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledWithNew")); }); - it("fails when spyCall failed", function () { + it("fails when spyCall failed", function() { var spy = sinonSpy(); spy(); new spy(); // eslint-disable-line no-new, new-cap - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWithNew(spy.firstCall); }); @@ -641,13 +659,13 @@ describe("assert", function () { }); }); - describe(".alwaysCalledWithNew", function () { + describe(".alwaysCalledWithNew", function() { requiresValidFake("alwaysCalledWithNew"); - it("fails when method does not exist", function () { + it("fails when method does not exist", function() { sinonStub(this.stub, "alwaysCalledWithNew"); - assert.exception(function () { + assert.exception(function() { sinonAssert.alwaysCalledWithNew(null); }); @@ -655,29 +673,31 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("fails when method is not stub", function () { + it("fails when method is not stub", function() { sinonStub(this.stub, "alwaysCalledWithNew"); - assert.exception(function () { - sinonAssert.alwaysCalledWithNew(function () { return; }); + assert.exception(function() { + sinonAssert.alwaysCalledWithNew(function() { + return; + }); }); assert.isFalse(this.stub.alwaysCalledWithNew.called); assert(sinonAssert.fail.called); }); - it("fails when method fails", function () { + it("fails when method fails", function() { sinonStub(this.stub, "alwaysCalledWithNew").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.alwaysCalledWithNew(stub); }); assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { sinonStub(this.stub, "alwaysCalledWithNew").returns(true); var stub = this.stub; @@ -686,7 +706,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { new this.stub(); // eslint-disable-line no-new, new-cap sinonAssert.alwaysCalledWithNew(this.stub); @@ -695,13 +715,13 @@ describe("assert", function () { }); }); - describe(".calledWith", function () { - it("fails when method fails", function () { + describe(".calledWith", function() { + it("fails when method fails", function() { var object = {}; sinonStub(this.stub, "calledWith").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWith(stub, object, 1); }); @@ -709,12 +729,12 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { var object = {}; sinonStub(this.stub, "calledWith").returns(true); var stub = this.stub; - refute.exception(function () { + refute.exception(function() { sinonAssert.calledWith(stub, object, 1); }); @@ -722,7 +742,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { this.stub("yeah"); sinonAssert.calledWith(this.stub, "yeah"); @@ -730,7 +750,7 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledWith")); }); - it("works with spyCall", function () { + it("works with spyCall", function() { var spy = sinonSpy(); var object = {}; spy(); @@ -741,13 +761,13 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledWith")); }); - it("fails when spyCall failed", function () { + it("fails when spyCall failed", function() { var spy = sinonSpy(); var object = {}; spy(); spy(object); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWith(spy.lastCall, 1); }); @@ -755,13 +775,13 @@ describe("assert", function () { }); }); - describe(".calledWithExactly", function () { - it("fails when method fails", function () { + describe(".calledWithExactly", function() { + it("fails when method fails", function() { var object = {}; sinonStub(this.stub, "calledWithExactly").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWithExactly(stub, object, 1); }); @@ -769,12 +789,12 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { var object = {}; sinonStub(this.stub, "calledWithExactly").returns(true); var stub = this.stub; - refute.exception(function () { + refute.exception(function() { sinonAssert.calledWithExactly(stub, object, 1); }); @@ -782,7 +802,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { this.stub("yeah"); sinonAssert.calledWithExactly(this.stub, "yeah"); @@ -790,7 +810,7 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledWithExactly")); }); - it("works with spyCall", function () { + it("works with spyCall", function() { var spy = sinonSpy(); var object = {}; spy(); @@ -801,13 +821,13 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("calledWithExactly")); }); - it("fails when spyCall failed", function () { + it("fails when spyCall failed", function() { var spy = sinonSpy(); var object = {}; spy(); spy(object); - assert.exception(function () { + assert.exception(function() { sinonAssert.calledWithExactly(spy.lastCall, 1); }); @@ -815,13 +835,13 @@ describe("assert", function () { }); }); - describe(".neverCalledWith", function () { - it("fails when method fails", function () { + describe(".neverCalledWith", function() { + it("fails when method fails", function() { var object = {}; sinonStub(this.stub, "neverCalledWith").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.neverCalledWith(stub, object, 1); }); @@ -829,12 +849,12 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { var object = {}; sinonStub(this.stub, "neverCalledWith").returns(true); var stub = this.stub; - refute.exception(function () { + refute.exception(function() { sinonAssert.neverCalledWith(stub, object, 1); }); @@ -842,7 +862,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { this.stub("yeah"); sinonAssert.neverCalledWith(this.stub, "nah!"); @@ -851,12 +871,12 @@ describe("assert", function () { }); }); - describe(".threwTest", function () { - it("fails when method fails", function () { + describe(".threwTest", function() { + it("fails when method fails", function() { sinonStub(this.stub, "threw").returns(false); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.threw(stub, 1, 2); }); @@ -864,11 +884,11 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { sinonStub(this.stub, "threw").returns(true); var stub = this.stub; - refute.exception(function () { + refute.exception(function() { sinonAssert.threw(stub, 1, 2); }); @@ -876,7 +896,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { sinonStub(this.stub, "threw").returns(true); this.stub(); sinonAssert.threw(this.stub); @@ -885,9 +905,9 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("threw")); }); - it("works with spyCall", function () { + it("works with spyCall", function() { var stub = sinonStub().throws("Error"); - assert.exception(function () { + assert.exception(function() { stub(); }); @@ -896,11 +916,11 @@ describe("assert", function () { assert(sinonAssert.pass.calledWith("threw")); }); - it("fails when spyCall failed", function () { + it("fails when spyCall failed", function() { var stub = sinonStub().returns("Error"); stub(); - assert.exception(function () { + assert.exception(function() { sinonAssert.threw(stub.firstCall, "Error"); }); @@ -908,33 +928,33 @@ describe("assert", function () { }); }); - describe(".callCount", function () { + describe(".callCount", function() { requiresValidFake("callCount"); - it("fails when method fails", function () { + it("fails when method fails", function() { this.stub(); this.stub(); var stub = this.stub; - assert.exception(function () { + assert.exception(function() { sinonAssert.callCount(stub, 3); }); assert(sinonAssert.fail.called); }); - it("passes when method doesn't fail", function () { + it("passes when method doesn't fail", function() { var stub = this.stub; this.stub.callCount = 3; - refute.exception(function () { + refute.exception(function() { sinonAssert.callCount(stub, 3); }); assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { this.stub(); sinonAssert.callCount(this.stub, 1); @@ -943,31 +963,33 @@ describe("assert", function () { }); }); - describe(".alwaysCalledOn", function () { - it("fails if method is missing", function () { - assert.exception(function () { + describe(".alwaysCalledOn", function() { + it("fails if method is missing", function() { + assert.exception(function() { sinonAssert.alwaysCalledOn(); }); }); - it("fails if method is not fake", function () { - assert.exception(function () { - sinonAssert.alwaysCalledOn(function () { return; }, {}); + it("fails if method is not fake", function() { + assert.exception(function() { + sinonAssert.alwaysCalledOn(function() { + return; + }, {}); }); }); - it("fails if stub returns false", function () { + it("fails if stub returns false", function() { var stub = sinonStub(); sinonStub(stub, "alwaysCalledOn").returns(false); - assert.exception(function () { + assert.exception(function() { sinonAssert.alwaysCalledOn(stub, {}); }); assert(sinonAssert.fail.called); }); - it("passes if stub returns true", function () { + it("passes if stub returns true", function() { var stub = sinonStub.create(); sinonStub(stub, "alwaysCalledOn").returns(true); @@ -976,7 +998,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { this.stub(); sinonAssert.alwaysCalledOn(this.stub, this); @@ -986,41 +1008,43 @@ describe("assert", function () { }); }); - describe(".alwaysCalledWith", function () { - beforeEach(function () { + describe(".alwaysCalledWith", function() { + beforeEach(function() { sinonStub(sinonAssert, "fail").throws(); sinonStub(sinonAssert, "pass"); }); - afterEach(function () { + afterEach(function() { sinonAssert.fail.restore(); sinonAssert.pass.restore(); }); - it("fails if method is missing", function () { - assert.exception(function () { + it("fails if method is missing", function() { + assert.exception(function() { sinonAssert.alwaysCalledWith(); }); }); - it("fails if method is not fake", function () { - assert.exception(function () { - sinonAssert.alwaysCalledWith(function () { return; }); + it("fails if method is not fake", function() { + assert.exception(function() { + sinonAssert.alwaysCalledWith(function() { + return; + }); }); }); - it("fails if stub returns false", function () { + it("fails if stub returns false", function() { var stub = sinonStub.create(); sinonStub(stub, "alwaysCalledWith").returns(false); - assert.exception(function () { + assert.exception(function() { sinonAssert.alwaysCalledWith(stub, {}, []); }); assert(sinonAssert.fail.called); }); - it("passes if stub returns true", function () { + it("passes if stub returns true", function() { var stub = sinonStub.create(); sinonStub(stub, "alwaysCalledWith").returns(true); @@ -1029,7 +1053,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var spy = sinonSpy(); spy("Hello"); sinonAssert.alwaysCalledWith(spy, "Hello"); @@ -1039,18 +1063,18 @@ describe("assert", function () { }); }); - describe(".alwaysCalledWithExactly", function () { - beforeEach(function () { + describe(".alwaysCalledWithExactly", function() { + beforeEach(function() { sinonStub(sinonAssert, "fail"); sinonStub(sinonAssert, "pass"); }); - afterEach(function () { + afterEach(function() { sinonAssert.fail.restore(); sinonAssert.pass.restore(); }); - it("fails if stub returns false", function () { + it("fails if stub returns false", function() { var stub = sinonStub.create(); sinonStub(stub, "alwaysCalledWithExactly").returns(false); @@ -1059,7 +1083,7 @@ describe("assert", function () { assert(sinonAssert.fail.called); }); - it("passes if stub returns true", function () { + it("passes if stub returns true", function() { var stub = sinonStub.create(); sinonStub(stub, "alwaysCalledWithExactly").returns(true); @@ -1068,7 +1092,7 @@ describe("assert", function () { assert.isFalse(sinonAssert.fail.called); }); - it("calls pass callback", function () { + it("calls pass callback", function() { var spy = sinonSpy(); spy("Hello"); sinonAssert.alwaysCalledWithExactly(spy, "Hello"); @@ -1078,8 +1102,8 @@ describe("assert", function () { }); }); - describe(".expose", function () { - it("exposes asserts into object", function () { + describe(".expose", function() { + it("exposes asserts into object", function() { var test = {}; sinonAssert.expose(test); @@ -1093,7 +1117,7 @@ describe("assert", function () { assert.isFunction(test.assertCallCount); }); - it("exposes asserts into global", function () { + it("exposes asserts into global", function() { sinonAssert.expose(this.global, { includeFail: false }); @@ -1109,13 +1133,13 @@ describe("assert", function () { /*eslint-enable no-undef*/ }); - it("fails exposed asserts without errors", function () { + it("fails exposed asserts without errors", function() { sinonAssert.expose(this.global, { includeFail: false }); assert.exception( - function () { + function() { assertCalled(sinonSpy()); // eslint-disable-line no-undef }, { @@ -1124,7 +1148,7 @@ describe("assert", function () { ); }); - it("exposes asserts into object without prefixes", function () { + it("exposes asserts into object without prefixes", function() { var test = {}; sinonAssert.expose(test, { prefix: "" }); @@ -1139,7 +1163,7 @@ describe("assert", function () { assert.isFunction(test.callCount); }); - it("does not expose 'expose'", function () { + it("does not expose 'expose'", function() { var test = {}; sinonAssert.expose(test, { prefix: "" }); @@ -1147,30 +1171,39 @@ describe("assert", function () { refute(test.expose, "Expose should not be exposed"); }); - it("throws if target is undefined", function () { - assert.exception(function () { - sinonAssert.expose(); - }, {name: "TypeError"}); + it("throws if target is undefined", function() { + assert.exception( + function() { + sinonAssert.expose(); + }, + { name: "TypeError" } + ); }); - it("throws if target is null", function () { - assert.exception(function () { - sinonAssert.expose(null); - }, {name: "TypeError"}); + it("throws if target is null", function() { + assert.exception( + function() { + sinonAssert.expose(null); + }, + { name: "TypeError" } + ); }); }); - describe("message", function () { - beforeEach(function () { + describe("message", function() { + beforeEach(function() { this.obj = { - doSomething: function () { return; } + doSomething: function() { + return; + } }; sinonSpy(this.obj, "doSomething"); /*eslint consistent-return: "off"*/ - this.message = function (method) { - try { // eslint-disable-line no-restricted-syntax + this.message = function(method) { + // eslint-disable-next-line no-restricted-syntax + try { sinonAssert[method].apply(sinonAssert, [].slice.call(arguments, 1)); } catch (e) { return e.message; @@ -1178,46 +1211,59 @@ describe("assert", function () { }; }); - it("assert.called exception message", function () { - assert.equals(this.message("called", this.obj.doSomething), - "expected doSomething to have been called at " + - "least once but was never called"); + it("assert.called exception message", function() { + assert.equals( + this.message("called", this.obj.doSomething), + "expected doSomething to have been called at " + "least once but was never called" + ); }); - it("assert.notCalled exception message one call", function () { + it("assert.notCalled exception message one call", function() { this.obj.doSomething(); - assert.equals(this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), - "expected doSomething to not have been called " + - "but was called once\n doSomething()"); + assert.equals( + this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), + "expected doSomething to not have been called " + "but was called once\n doSomething()" + ); }); - it("assert.notCalled exception message four calls", function () { + it("assert.notCalled exception message four calls", function() { this.obj.doSomething(); this.obj.doSomething(); this.obj.doSomething(); this.obj.doSomething(); - assert.equals(this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), + assert.equals( + this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), "expected doSomething to not have been called " + - "but was called 4 times\n doSomething()\n " + - "doSomething()\n doSomething()\n doSomething()"); + "but was called 4 times\n doSomething()\n " + + "doSomething()\n doSomething()\n doSomething()" + ); }); - it("assert.notCalled exception message with calls with arguments", function () { + it("assert.notCalled exception message with calls with arguments", function() { this.obj.doSomething(); this.obj.doSomething(3); this.obj.doSomething(42, 1); this.obj.doSomething(); - assert.equals(this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), + assert.equals( + this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), "expected doSomething to not have been called " + - "but was called 4 times\n doSomething()\n " + - "doSomething(3)\n doSomething(42, 1)\n doSomething()"); + "but was called 4 times\n doSomething()\n " + + "doSomething(3)\n doSomething(42, 1)\n doSomething()" + ); }); - it("assert.callOrder exception message", function () { - var obj = { doop: function () { return; }, foo: function () { return; } }; + it("assert.callOrder exception message", function() { + var obj = { + doop: function() { + return; + }, + foo: function() { + return; + } + }; sinonSpy(obj, "doop"); sinonSpy(obj, "foo"); @@ -1227,13 +1273,21 @@ describe("assert", function () { var message = this.message("callOrder", this.obj.doSomething, obj.doop, obj.foo); - assert.equals(message, - "expected doSomething, doop, foo to be called in " + - "order but were called as doop, doSomething, foo"); + assert.equals( + message, + "expected doSomething, doop, foo to be called in " + "order but were called as doop, doSomething, foo" + ); }); - it("assert.callOrder with missing first call exception message", function () { - var obj = { doop: function () { return; }, foo: function () { return; } }; + it("assert.callOrder with missing first call exception message", function() { + var obj = { + doop: function() { + return; + }, + foo: function() { + return; + } + }; sinonSpy(obj, "doop"); sinonSpy(obj, "foo"); @@ -1241,13 +1295,18 @@ describe("assert", function () { var message = this.message("callOrder", obj.doop, obj.foo); - assert.equals(message, - "expected doop, foo to be called in " + - "order but were called as foo"); + assert.equals(message, "expected doop, foo to be called in " + "order but were called as foo"); }); - it("assert.callOrder with missing last call exception message", function () { - var obj = { doop: function () { return; }, foo: function () { return; } }; + it("assert.callOrder with missing last call exception message", function() { + var obj = { + doop: function() { + return; + }, + foo: function() { + return; + } + }; sinonSpy(obj, "doop"); sinonSpy(obj, "foo"); @@ -1255,43 +1314,46 @@ describe("assert", function () { var message = this.message("callOrder", obj.doop, obj.foo); - assert.equals(message, - "expected doop, foo to be called in " + - "order but were called as doop"); + assert.equals(message, "expected doop, foo to be called in " + "order but were called as doop"); }); - it("assert.callCount exception message", function () { + it("assert.callCount exception message", function() { this.obj.doSomething(); - assert.equals(this.message("callCount", this.obj.doSomething, 3).replace(/ at.*/g, ""), - "expected doSomething to be called thrice but was called " + - "once\n doSomething()"); + assert.equals( + this.message("callCount", this.obj.doSomething, 3).replace(/ at.*/g, ""), + "expected doSomething to be called thrice but was called " + "once\n doSomething()" + ); }); - it("assert.calledOnce exception message", function () { + it("assert.calledOnce exception message", function() { this.obj.doSomething(); this.obj.doSomething(); - assert.equals(this.message("calledOnce", this.obj.doSomething).replace(/ at.*/g, ""), - "expected doSomething to be called once but was called " + - "twice\n doSomething()\n doSomething()"); + assert.equals( + this.message("calledOnce", this.obj.doSomething).replace(/ at.*/g, ""), + "expected doSomething to be called once but was called " + "twice\n doSomething()\n doSomething()" + ); this.obj.doSomething(); - assert.equals(this.message("calledOnce", this.obj.doSomething).replace(/ at.*/g, ""), + assert.equals( + this.message("calledOnce", this.obj.doSomething).replace(/ at.*/g, ""), "expected doSomething to be called once but was called " + - "thrice\n doSomething()\n doSomething()\n doSomething()"); + "thrice\n doSomething()\n doSomething()\n doSomething()" + ); }); - it("assert.calledTwice exception message", function () { + it("assert.calledTwice exception message", function() { this.obj.doSomething(); - assert.equals(this.message("calledTwice", this.obj.doSomething).replace(/ at.*/g, ""), - "expected doSomething to be called twice but was called " + - "once\n doSomething()"); + assert.equals( + this.message("calledTwice", this.obj.doSomething).replace(/ at.*/g, ""), + "expected doSomething to be called twice but was called " + "once\n doSomething()" + ); }); - it("assert.calledThrice exception message", function () { + it("assert.calledThrice exception message", function() { this.obj.doSomething(); this.obj.doSomething(); this.obj.doSomething(); @@ -1304,18 +1366,18 @@ describe("assert", function () { ); }); - it("assert.calledOn exception message", function () { - this.obj.toString = function () { + it("assert.calledOn exception message", function() { + this.obj.toString = function() { return "[Oh yeah]"; }; var obj = { - toString: function () { + toString: function() { return "[Oh no]"; } }; var obj2 = { - toString: function () { + toString: function() { return "[Oh well]"; } }; @@ -1329,18 +1391,18 @@ describe("assert", function () { ); }); - it("assert.alwaysCalledOn exception message", function () { - this.obj.toString = function () { + it("assert.alwaysCalledOn exception message", function() { + this.obj.toString = function() { return "[Oh yeah]"; }; var obj = { - toString: function () { + toString: function() { return "[Oh no]"; } }; var obj2 = { - toString: function () { + toString: function() { return "[Oh well]"; } }; @@ -1356,55 +1418,70 @@ describe("assert", function () { ); }); - it("assert.calledWithNew exception message", function () { + it("assert.calledWithNew exception message", function() { this.obj.doSomething(); - assert.equals(this.message("calledWithNew", this.obj.doSomething), - "expected doSomething to be called with new"); + assert.equals( + this.message("calledWithNew", this.obj.doSomething), + "expected doSomething to be called with new" + ); }); - it("assert.alwaysCalledWithNew exception message", function () { + it("assert.alwaysCalledWithNew exception message", function() { new this.obj.doSomething(); // eslint-disable-line no-new, new-cap this.obj.doSomething(); - assert.equals(this.message("alwaysCalledWithNew", this.obj.doSomething), - "expected doSomething to always be called with new"); + assert.equals( + this.message("alwaysCalledWithNew", this.obj.doSomething), + "expected doSomething to always be called with new" + ); }); - it("assert.calledWith exception message", function () { + it("assert.calledWith exception message", function() { this.obj.doSomething(4, 3, "hey"); - assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""), + assert.equals( + this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""), "expected doSomething to be called with arguments \n" + - color.red("4") + " " + color.green("1") + " \n" + - "3\n" + - "hey"); + color.red("4") + + " " + + color.green("1") + + " \n" + + "3\n" + + "hey" + ); }); - it("assert.calledWith exception message with multiple calls", function () { + it("assert.calledWith exception message with multiple calls", function() { this.obj.doSomething(4, 3, "hey"); this.obj.doSomething(1, 3, "not"); - assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""), + assert.equals( + this.message("calledWith", this.obj.doSomething, 1, 3, "hey").replace(/ at.*/g, ""), "expected doSomething to be called with arguments \n" + - "Call 1:\n" + - color.red("4") + " " + color.green("1") + " \n" + - "3\n" + - "hey\n" + - "Call 2:\n" + - "1\n" + - "3\n" + - color.red("not") + " " + color.green("hey") + " "); + "Call 1:\n" + + color.red("4") + + " " + + color.green("1") + + " \n" + + "3\n" + + "hey\n" + + "Call 2:\n" + + "1\n" + + "3\n" + + color.red("not") + + " " + + color.green("hey") + + " " + ); }); - it("assert.calledWith exception message with large object arguments", function () { + it("assert.calledWith exception message with large object arguments", function() { var calledArg = [ { first: "a", - second: {nest: true}, - third: [ - {fourth: {nest: true}} - ], + second: { nest: true }, + third: [{ fourth: { nest: true } }], mismatchKey: true }, "fifth" @@ -1414,295 +1491,360 @@ describe("assert", function () { var expectedArg = [ { first: "a", - second: {nest: true}, - third: [ - {fourth: {nest: false}} - ], + second: { nest: true }, + third: [{ fourth: { nest: false } }], mismatchKeyX: true }, "fifth" ]; - assert.equals(this.message("calledWith", this.obj.doSomething, expectedArg).replace(/ at.*/g, ""), + assert.equals( + this.message("calledWith", this.obj.doSomething, expectedArg).replace(/ at.*/g, ""), "expected doSomething to be called with arguments \n" + - "[{\n" + - " first: \"a\",\n" + - color.red(" mismatchKey: true,\n") + - color.green(" mismatchKeyX: true,\n") + - " second: { nest: true },\n" + - color.red(" third: [{ fourth: { nest: true } }]\n") + - color.green(" third: [{ fourth: { nest: false } }]\n") + - "}, \"fifth\"]"); + "[{\n" + + ' first: "a",\n' + + color.red(" mismatchKey: true,\n") + + color.green(" mismatchKeyX: true,\n") + + " second: { nest: true },\n" + + color.red(" third: [{ fourth: { nest: true } }]\n") + + color.green(" third: [{ fourth: { nest: false } }]\n") + + '}, "fifth"]' + ); }); - it("assert.calledWith exception message with a missing argument", function () { + it("assert.calledWith exception message with a missing argument", function() { this.obj.doSomething(4); - assert.equals(this.message("calledWith", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), + assert.equals( + this.message("calledWith", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), "expected doSomething to be called with arguments \n" + - color.red("4") + " " + color.green("1") + " \n" + - color.green("3")); + color.red("4") + + " " + + color.green("1") + + " \n" + + color.green("3") + ); }); - it("assert.calledWith exception message with an excess argument", function () { + it("assert.calledWith exception message with an excess argument", function() { this.obj.doSomething(4, 3); - assert.equals(this.message("calledWith", this.obj.doSomething, 1).replace(/ at.*/g, ""), + assert.equals( + this.message("calledWith", this.obj.doSomething, 1).replace(/ at.*/g, ""), "expected doSomething to be called with arguments \n" + - color.red("4") + " " + color.green("1") + " \n" + - color.red("3")); + color.red("4") + + " " + + color.green("1") + + " \n" + + color.red("3") + ); }); - it("assert.calledWith match.any exception message", function () { + it("assert.calledWith match.any exception message", function() { this.obj.doSomething(true, true); assert.equals( this.message("calledWith", this.obj.doSomething, sinonMatch.any, false).replace(/ at.*/g, ""), "expected doSomething to be called with arguments \n" + - "true any\n" + - color.red("true") + " " + color.green("false") + " "); + "true any\n" + + color.red("true") + + " " + + color.green("false") + + " " + ); }); - it("assert.calledWith match.defined exception message", function () { + it("assert.calledWith match.defined exception message", function() { this.obj.doSomething(); assert.equals( this.message("calledWith", this.obj.doSomething, sinonMatch.defined).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("defined")); + "expected doSomething to be called with arguments \n " + color.red("defined") + ); }); - it("assert.calledWith match.truthy exception message", function () { + it("assert.calledWith match.truthy exception message", function() { this.obj.doSomething(); assert.equals( this.message("calledWith", this.obj.doSomething, sinonMatch.truthy).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("truthy")); + "expected doSomething to be called with arguments \n " + color.red("truthy") + ); }); - it("assert.calledWith match.falsy exception message", function () { + it("assert.calledWith match.falsy exception message", function() { this.obj.doSomething(true); - assert.equals(this.message("calledWith", this.obj.doSomething, sinonMatch.falsy).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n" + - color.green("true") + " " + color.red("falsy")); + assert.equals( + this.message("calledWith", this.obj.doSomething, sinonMatch.falsy).replace(/ at.*/g, ""), + "expected doSomething to be called with arguments \n" + color.green("true") + " " + color.red("falsy") + ); }); - it("assert.calledWith match.same exception message", function () { + it("assert.calledWith match.same exception message", function() { this.obj.doSomething(); assert.equals( this.message("calledWith", this.obj.doSomething, sinonMatch.same(1)).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("same(1)")); + "expected doSomething to be called with arguments \n " + color.red("same(1)") + ); }); - it("assert.calledWith match.typeOf exception message", function () { + it("assert.calledWith match.typeOf exception message", function() { this.obj.doSomething(); var matcher = sinonMatch.typeOf("string"); assert.equals( this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("typeOf(\"string\")")); + "expected doSomething to be called with arguments \n " + color.red('typeOf("string")') + ); }); - it("assert.calledWith match.instanceOf exception message", function () { + it("assert.calledWith match.instanceOf exception message", function() { this.obj.doSomething(); - var matcher = sinonMatch.instanceOf(function CustomType() { return; }); + var matcher = sinonMatch.instanceOf(function CustomType() { + return; + }); assert.equals( this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("instanceOf(CustomType)")); + "expected doSomething to be called with arguments \n " + color.red("instanceOf(CustomType)") + ); }); - it("assert.calledWith match object exception message", function () { + it("assert.calledWith match object exception message", function() { this.obj.doSomething(); var matcher = sinonMatch({ some: "value", and: 123 }); assert.equals( this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("match(some: value, and: 123)")); + "expected doSomething to be called with arguments \n " + color.red("match(some: value, and: 123)") + ); }); - it("assert.calledWith match boolean exception message", function () { + it("assert.calledWith match boolean exception message", function() { this.obj.doSomething(); - assert.equals(this.message("calledWith", this.obj.doSomething, sinonMatch(true)).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("match(true)")); + assert.equals( + this.message("calledWith", this.obj.doSomething, sinonMatch(true)).replace(/ at.*/g, ""), + "expected doSomething to be called with arguments \n " + color.red("match(true)") + ); }); - it("assert.calledWith match number exception message", function () { + it("assert.calledWith match number exception message", function() { this.obj.doSomething(); - assert.equals(this.message("calledWith", this.obj.doSomething, sinonMatch(123)).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("match(123)")); + assert.equals( + this.message("calledWith", this.obj.doSomething, sinonMatch(123)).replace(/ at.*/g, ""), + "expected doSomething to be called with arguments \n " + color.red("match(123)") + ); }); - it("assert.calledWith match string exception message", function () { + it("assert.calledWith match string exception message", function() { this.obj.doSomething(); var matcher = sinonMatch("Sinon"); - assert.equals(this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("match(\"Sinon\")")); + assert.equals( + this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), + "expected doSomething to be called with arguments \n " + color.red('match("Sinon")') + ); }); - it("assert.calledWith match regexp exception message", function () { + it("assert.calledWith match regexp exception message", function() { this.obj.doSomething(); assert.equals( this.message("calledWith", this.obj.doSomething, sinonMatch(/[a-z]+/)).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("match(/[a-z]+/)")); + "expected doSomething to be called with arguments \n " + color.red("match(/[a-z]+/)") + ); }); - it("assert.calledWith match test function exception message", function () { + it("assert.calledWith match test function exception message", function() { this.obj.doSomething(); - var matcher = sinonMatch({ test: function custom() { return; } }); + var matcher = sinonMatch({ + test: function custom() { + return; + } + }); assert.equals( this.message("calledWith", this.obj.doSomething, matcher).replace(/ at.*/g, ""), - "expected doSomething to be called with arguments \n " + color.red("match(custom)")); + "expected doSomething to be called with arguments \n " + color.red("match(custom)") + ); }); - it("assert.calledWithMatch exception message", function () { + it("assert.calledWithMatch exception message", function() { this.obj.doSomething(1, 3, "hey"); - assert.equals(this.message("calledWithMatch", this.obj.doSomething, 4, 3, "hey").replace(/ at.*/g, ""), + assert.equals( + this.message("calledWithMatch", this.obj.doSomething, 4, 3, "hey").replace(/ at.*/g, ""), "expected doSomething to be called with match \n" + - color.red("1") + " " + color.green("4") + " \n" + - "3\n" + - "hey"); + color.red("1") + + " " + + color.green("4") + + " \n" + + "3\n" + + "hey" + ); }); - it("assert.alwaysCalledWith exception message", function () { + it("assert.alwaysCalledWith exception message", function() { this.obj.doSomething(1, 3, "hey"); this.obj.doSomething(1, "hey"); - assert.equals(this.message("alwaysCalledWith", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""), + assert.equals( + this.message("alwaysCalledWith", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""), "expected doSomething to always be called with arguments \n" + - "Call 1:\n" + - "1\n" + - color.red("3") + " " + color.green("hey") + " \n" + - color.red("hey") + "\n" + - "Call 2:\n" + - "1\n" + - "hey"); + "Call 1:\n" + + "1\n" + + color.red("3") + + " " + + color.green("hey") + + " \n" + + color.red("hey") + + "\n" + + "Call 2:\n" + + "1\n" + + "hey" + ); }); - it("assert.alwaysCalledWithMatch exception message", function () { + it("assert.alwaysCalledWithMatch exception message", function() { this.obj.doSomething(1, 3, "hey"); this.obj.doSomething(1, "hey"); assert.equals( this.message("alwaysCalledWithMatch", this.obj.doSomething, 1, "hey").replace(/ at.*/g, ""), "expected doSomething to always be called with match \n" + - "Call 1:\n" + - "1\n" + - color.red("3") + " " + color.green("hey") + " \n" + - color.red("hey") + "\n" + - "Call 2:\n" + - "1\n" + - "hey"); + "Call 1:\n" + + "1\n" + + color.red("3") + + " " + + color.green("hey") + + " \n" + + color.red("hey") + + "\n" + + "Call 2:\n" + + "1\n" + + "hey" + ); }); - it("assert.calledWithExactly exception message", function () { + it("assert.calledWithExactly exception message", function() { this.obj.doSomething(1, 3, "hey"); - assert.equals(this.message("calledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), - "expected doSomething to be called with exact arguments \n" + - "1\n" + - "3\n" + - color.red("hey")); + assert.equals( + this.message("calledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), + "expected doSomething to be called with exact arguments \n" + "1\n" + "3\n" + color.red("hey") + ); }); - it("assert.alwaysCalledWithExactly exception message", function () { + it("assert.alwaysCalledWithExactly exception message", function() { this.obj.doSomething(1, 3, "hey"); this.obj.doSomething(1, 3); - assert.equals(this.message("alwaysCalledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), + assert.equals( + this.message("alwaysCalledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), "expected doSomething to always be called with exact arguments \n" + - "Call 1:\n" + - "1\n" + - "3\n" + - color.red("hey") + "\n" + - "Call 2:\n" + - "1\n" + - "3"); + "Call 1:\n" + + "1\n" + + "3\n" + + color.red("hey") + + "\n" + + "Call 2:\n" + + "1\n" + + "3" + ); }); - it("assert.neverCalledWith exception message", function () { + it("assert.neverCalledWith exception message", function() { this.obj.doSomething(1, 2, 3); - assert.equals(this.message("neverCalledWith", this.obj.doSomething, 1, 2).replace(/ at.*/g, ""), - "expected doSomething to never be called with " + - "arguments 1, 2\n doSomething(1, 2, 3)"); + assert.equals( + this.message("neverCalledWith", this.obj.doSomething, 1, 2).replace(/ at.*/g, ""), + "expected doSomething to never be called with " + "arguments 1, 2\n doSomething(1, 2, 3)" + ); }); - it("assert.neverCalledWithMatch exception message", function () { + it("assert.neverCalledWithMatch exception message", function() { this.obj.doSomething(1, 2, 3); - assert.equals(this.message("neverCalledWithMatch", this.obj.doSomething, 1, 2).replace(/ at.*/g, ""), - "expected doSomething to never be called with match " + - "1, 2\n doSomething(1, 2, 3)"); + assert.equals( + this.message("neverCalledWithMatch", this.obj.doSomething, 1, 2).replace(/ at.*/g, ""), + "expected doSomething to never be called with match " + "1, 2\n doSomething(1, 2, 3)" + ); }); - it("assert.threw exception message", function () { + it("assert.threw exception message", function() { this.obj.doSomething(1, 3, "hey"); this.obj.doSomething(1, 3); - assert.equals(this.message("threw", this.obj.doSomething).replace(/ at.*/g, ""), - "doSomething did not throw exception\n" + - " doSomething(1, 3, hey)\n doSomething(1, 3)"); + assert.equals( + this.message("threw", this.obj.doSomething).replace(/ at.*/g, ""), + "doSomething did not throw exception\n" + " doSomething(1, 3, hey)\n doSomething(1, 3)" + ); }); - it("assert.alwaysThrew exception message", function () { + it("assert.alwaysThrew exception message", function() { this.obj.doSomething(1, 3, "hey"); this.obj.doSomething(1, 3); - assert.equals(this.message("alwaysThrew", this.obj.doSomething).replace(/ at.*/g, ""), - "doSomething did not always throw exception\n" + - " doSomething(1, 3, hey)\n doSomething(1, 3)"); + assert.equals( + this.message("alwaysThrew", this.obj.doSomething).replace(/ at.*/g, ""), + "doSomething did not always throw exception\n" + " doSomething(1, 3, hey)\n doSomething(1, 3)" + ); }); - it("assert.match exception message", function () { - assert.equals(this.message("match", { foo: 1 }, [1, 3]), - "expected value to match\n" + - " expected = [1, 3]\n" + - " actual = { foo: 1 }"); + it("assert.match exception message", function() { + assert.equals( + this.message("match", { foo: 1 }, [1, 3]), + "expected value to match\n" + " expected = [1, 3]\n" + " actual = { foo: 1 }" + ); }); }); if (typeof Symbol === "function") { - describe("with symbol method names", function () { + describe("with symbol method names", function() { var obj = {}; function setupSymbol(symbol) { - obj[symbol] = function () { return; }; + obj[symbol] = function() { + return; + }; sinonSpy(obj, symbol); } function createExceptionMessage(method, arg) { - try { // eslint-disable-line no-restricted-syntax + // eslint-disable-next-line no-restricted-syntax + try { sinonAssert[method](arg); } catch (e) { return e.message; } } - it("should use the symbol's description in exception messages", function () { + it("should use the symbol's description in exception messages", function() { var symbol = Symbol("Something Symbolic"); setupSymbol(symbol); - assert.equals(createExceptionMessage("called", obj[symbol]), - "expected Symbol(Something Symbolic) to have been " + - "called at least once but was never called"); + assert.equals( + createExceptionMessage("called", obj[symbol]), + "expected Symbol(Something Symbolic) to have been " + "called at least once but was never called" + ); }); - it("should indicate that an assertion failure with a symbol method name " + - "occured in exception messages, even if the symbol has no description", function () { - var symbol = Symbol(); - setupSymbol(symbol); + it( + "should indicate that an assertion failure with a symbol method name " + + "occured in exception messages, even if the symbol has no description", + function() { + var symbol = Symbol(); + setupSymbol(symbol); - assert.equals(createExceptionMessage("called", obj[symbol]), - "expected Symbol() to have been " + - "called at least once but was never called"); - }); + assert.equals( + createExceptionMessage("called", obj[symbol]), + "expected Symbol() to have been " + "called at least once but was never called" + ); + } + ); }); } }); diff --git a/test/behavior-test.js b/test/behavior-test.js index bec06e246..a15b132ed 100644 --- a/test/behavior-test.js +++ b/test/behavior-test.js @@ -3,9 +3,9 @@ var sinon = require("../lib/sinon"); var assert = require("@sinonjs/referee").assert; -describe("behaviors", function () { - it("adds and uses a custom behavior", function () { - sinon.addBehavior("returnsNum", function (fake, n) { +describe("behaviors", function() { + it("adds and uses a custom behavior", function() { + sinon.addBehavior("returnsNum", function(fake, n) { fake.returns(n); }); diff --git a/test/call-test.js b/test/call-test.js index cd6a32bab..2277dc4b0 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -11,9 +11,19 @@ var refute = referee.refute; function spyCallSetUp() { this.thisValue = {}; this.args = [{}, [], new Error(), 3]; - this.returnValue = function () { return; }; - this.call = sinonSpyCall(function () { return; }, this.thisValue, - this.args, this.returnValue, null, 0); + this.returnValue = function() { + return; + }; + this.call = sinonSpyCall( + function() { + return; + }, + this.thisValue, + this.args, + this.returnValue, + null, + 0 + ); } function spyCallCallSetup() { @@ -23,39 +33,39 @@ function spyCallCallSetup() { } function spyCallCalledTests(method) { - return function () { + return function() { // eslint-disable-next-line mocha/no-top-level-hooks beforeEach(spyCallSetUp); - it("returns true if all args match", function () { + it("returns true if all args match", function() { var args = this.args; assert(this.call[method](args[0], args[1], args[2])); }); - it("returns true if first args match", function () { + it("returns true if first args match", function() { var args = this.args; assert(this.call[method](args[0], args[1])); }); - it("returns true if first arg match", function () { + it("returns true if first arg match", function() { var args = this.args; assert(this.call[method](args[0])); }); - it("returns true for no args", function () { + it("returns true for no args", function() { assert(this.call[method]()); }); - it("returns false for too many args", function () { + it("returns false for too many args", function() { var args = this.args; assert.isFalse(this.call[method](args[0], args[1], args[2], args[3], {})); }); - it("returns false for wrong arg", function () { + it("returns false for wrong arg", function() { var args = this.args; assert.isFalse(this.call[method](args[0], args[2])); @@ -64,39 +74,39 @@ function spyCallCalledTests(method) { } function spyCallNotCalledTests(method) { - return function () { + return function() { // eslint-disable-next-line mocha/no-top-level-hooks, mocha/no-sibling-hooks beforeEach(spyCallSetUp); - it("returns false if all args match", function () { + it("returns false if all args match", function() { var args = this.args; assert.isFalse(this.call[method](args[0], args[1], args[2])); }); - it("returns false if first args match", function () { + it("returns false if first args match", function() { var args = this.args; assert.isFalse(this.call[method](args[0], args[1])); }); - it("returns false if first arg match", function () { + it("returns false if first arg match", function() { var args = this.args; assert.isFalse(this.call[method](args[0])); }); - it("returns false for no args", function () { + it("returns false for no args", function() { assert.isFalse(this.call[method]()); }); - it("returns true for too many args", function () { + it("returns true for too many args", function() { var args = this.args; assert(this.call[method](args[0], args[1], args[2], args[3], {})); }); - it("returns true for wrong arg", function () { + it("returns true for wrong arg", function() { var args = this.args; assert(this.call[method](args[0], args[2])); @@ -104,13 +114,11 @@ function spyCallNotCalledTests(method) { }; } - -describe("sinonSpy.call", function () { - - describe("call object", function () { +describe("sinonSpy.call", function() { + describe("call object", function() { beforeEach(spyCallSetUp); - it("gets call object", function () { + it("gets call object", function() { var spy = sinonSpy.create(); spy(); var firstCall = spy.getCall(0); @@ -120,27 +128,42 @@ describe("sinonSpy.call", function () { assert.isFunction(firstCall.returned); }); - it("stores given call id", function () { - var call = sinonSpyCall(function () { return; }, {}, [], null, null, 42); + it("stores given call id", function() { + var call = sinonSpyCall( + function() { + return; + }, + {}, + [], + null, + null, + 42 + ); assert.same(call.callId, 42); }); - it("throws if callId is undefined", function () { - assert.exception(function () { - sinonSpyCall.create(function () { return; }, {}, []); + it("throws if callId is undefined", function() { + assert.exception(function() { + sinonSpyCall.create( + function() { + return; + }, + {}, + [] + ); }); }); // This is actually a spy test: - it("records ascending call id's", function () { + it("records ascending call id's", function() { var spy = sinonSpy(); spy(); assert(this.call.callId < spy.getCall(0).callId); }); - it("exposes thisValue property", function () { + it("exposes thisValue property", function() { var spy = sinonSpy(); var obj = {}; spy.call(obj); @@ -148,13 +171,13 @@ describe("sinonSpy.call", function () { assert.same(spy.getCall(0).thisValue, obj); }); - it("has methods to test relative ordering", function () { + it("has methods to test relative ordering", function() { var spy = sinonSpy(); for (var i = 0; i < 4; i++) { spy.call({}); } - var calls = [0, 1, 2, 3].map(function (idx) { + var calls = [0, 1, 2, 3].map(function(idx) { return spy.getCall(idx); }); @@ -174,14 +197,14 @@ describe("sinonSpy.call", function () { }); }); - describe("call calledOn", function () { + describe("call calledOn", function() { beforeEach(spyCallSetUp); - it("calledOn should return true", function () { + it("calledOn should return true", function() { assert(this.call.calledOn(this.thisValue)); }); - it("calledOn should return false", function () { + it("calledOn should return false", function() { assert.isFalse(this.call.calledOn({})); }); }); @@ -191,50 +214,68 @@ describe("sinonSpy.call", function () { describe("call.notCalledWith", spyCallNotCalledTests("notCalledWith")); describe("call.notCalledWithMatch", spyCallNotCalledTests("notCalledWithMatch")); - describe("call.calledWithExactly", function () { + describe("call.calledWithExactly", function() { beforeEach(spyCallSetUp); - it("returns true when all args match", function () { + it("returns true when all args match", function() { var args = this.args; assert(this.call.calledWithExactly(args[0], args[1], args[2], args[3])); }); - it("returns false for too many args", function () { + it("returns false for too many args", function() { var args = this.args; assert.isFalse(this.call.calledWithExactly(args[0], args[1], args[2], args[3], {})); }); - it("returns false for too few args", function () { + it("returns false for too few args", function() { var args = this.args; assert.isFalse(this.call.calledWithExactly(args[0], args[1])); }); - it("returns false for unmatching args", function () { + it("returns false for unmatching args", function() { var args = this.args; assert.isFalse(this.call.calledWithExactly(args[0], args[1], args[1])); }); - it("returns true for no arguments", function () { - var call = sinonSpyCall(function () { return; }, {}, [], null, null, 0); + it("returns true for no arguments", function() { + var call = sinonSpyCall( + function() { + return; + }, + {}, + [], + null, + null, + 0 + ); assert(call.calledWithExactly()); }); - it("returns false when called with no args but matching one", function () { - var call = sinonSpyCall(function () { return; }, {}, [], null, null, 0); + it("returns false when called with no args but matching one", function() { + var call = sinonSpyCall( + function() { + return; + }, + {}, + [], + null, + null, + 0 + ); assert.isFalse(call.calledWithExactly({})); }); }); - describe("call.callArg", function () { + describe("call.callArg", function() { beforeEach(spyCallCallSetup); - it("calls argument at specified index", function () { + it("calls argument at specified index", function() { var callback = sinonSpy(); this.args.push(1, 2, callback); @@ -243,25 +284,31 @@ describe("sinonSpy.call", function () { assert(callback.called); }); - it("throws if argument at specified index is not callable", function () { + it("throws if argument at specified index is not callable", function() { this.args.push(1); var call = this.call; - assert.exception(function () { - call.callArg(0); - }, {message: "Expected argument at position 0 to be a Function, but was number"}); + assert.exception( + function() { + call.callArg(0); + }, + { message: "Expected argument at position 0 to be a Function, but was number" } + ); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var call = this.call; - assert.exception(function () { - call.callArg(); - }, {name: "TypeError"}); + assert.exception( + function() { + call.callArg(); + }, + { name: "TypeError" } + ); }); - it("returns callbacks return value", function () { - var callback = sinonSpy(function () { + it("returns callbacks return value", function() { + var callback = sinonSpy(function() { return "useful value"; }); this.args.push(1, 2, callback); @@ -271,19 +318,22 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var call = this.call; - assert.exception(function () { - call.callArg({}); - }, {name: "TypeError"}); + assert.exception( + function() { + call.callArg({}); + }, + { name: "TypeError" } + ); }); }); - describe("call.callArgOn", function () { + describe("call.callArgOn", function() { beforeEach(spyCallCallSetup); - it("calls argument at specified index", function () { + it("calls argument at specified index", function() { var callback = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; this.args.push(1, 2, callback); @@ -294,18 +344,21 @@ describe("sinonSpy.call", function () { assert(callback.calledOn(thisObj)); }); - it("throws if argument at specified index is not callable", function () { + it("throws if argument at specified index is not callable", function() { var thisObj = { name1: "value1", name2: "value2" }; this.args.push(1); var call = this.call; - assert.exception(function () { - call.callArgOn(0, thisObj); - }, {message: "Expected argument at position 0 to be a Function, but was number"}); + assert.exception( + function() { + call.callArgOn(0, thisObj); + }, + { message: "Expected argument at position 0 to be a Function, but was number" } + ); }); - it("returns callbacks return value", function () { - var callback = sinonSpy(function () { + it("returns callbacks return value", function() { + var callback = sinonSpy(function() { return "useful value"; }); var thisObj = { name1: "value1", name2: "value2" }; @@ -316,20 +369,23 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var thisObj = { name1: "value1", name2: "value2" }; var call = this.call; - assert.exception(function () { - call.callArgOn({}, thisObj); - }, {name: "TypeError"}); + assert.exception( + function() { + call.callArgOn({}, thisObj); + }, + { name: "TypeError" } + ); }); }); - describe("call.callArgWith", function () { + describe("call.callArgWith", function() { beforeEach(spyCallCallSetup); - it("calls argument at specified index with provided args", function () { + it("calls argument at specified index with provided args", function() { var object = {}; var callback = sinonSpy(); this.args.push(1, callback); @@ -339,7 +395,7 @@ describe("sinonSpy.call", function () { assert(callback.calledWith(object)); }); - it("calls callback without args", function () { + it("calls callback without args", function() { var callback = sinonSpy(); this.args.push(1, callback); @@ -348,7 +404,7 @@ describe("sinonSpy.call", function () { assert(callback.calledWith()); }); - it("calls callback wit multiple args", function () { + it("calls callback wit multiple args", function() { var object = {}; var array = []; var callback = sinonSpy(); @@ -359,9 +415,9 @@ describe("sinonSpy.call", function () { assert(callback.calledWith(object, array)); }); - it("returns callbacks return value", function () { + it("returns callbacks return value", function() { var object = {}; - var callback = sinonSpy(function () { + var callback = sinonSpy(function() { return "useful value"; }); this.args.push(1, callback); @@ -371,27 +427,33 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var call = this.call; - assert.exception(function () { - call.callArgWith(); - }, {name: "TypeError"}); + assert.exception( + function() { + call.callArgWith(); + }, + { name: "TypeError" } + ); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var call = this.call; - assert.exception(function () { - call.callArgWith({}); - }, {name: "TypeError"}); + assert.exception( + function() { + call.callArgWith({}); + }, + { name: "TypeError" } + ); }); }); - describe("call.callArgOnWith", function () { + describe("call.callArgOnWith", function() { beforeEach(spyCallCallSetup); - it("calls argument at specified index with provided args", function () { + it("calls argument at specified index with provided args", function() { var object = {}; var thisObj = { name1: "value1", name2: "value2" }; var callback = sinonSpy(); @@ -403,7 +465,7 @@ describe("sinonSpy.call", function () { assert(callback.calledOn(thisObj)); }); - it("calls callback without args", function () { + it("calls callback without args", function() { var callback = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; this.args.push(1, callback); @@ -414,7 +476,7 @@ describe("sinonSpy.call", function () { assert(callback.calledOn(thisObj)); }); - it("calls callback with multiple args", function () { + it("calls callback with multiple args", function() { var object = {}; var array = []; var thisObj = { name1: "value1", name2: "value2" }; @@ -427,10 +489,10 @@ describe("sinonSpy.call", function () { assert(callback.calledOn(thisObj)); }); - it("returns callbacks return value", function () { + it("returns callbacks return value", function() { var object = {}; var thisObj = { name1: "value1", name2: "value2" }; - var callback = sinonSpy(function () { + var callback = sinonSpy(function() { return "useful value"; }); this.args.push(1, callback); @@ -440,31 +502,41 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if argument at specified index is not callable", function () { + it("throws if argument at specified index is not callable", function() { var thisObj = { name1: "value1", name2: "value2" }; this.args.push(1, 2, 1); var call = this.call; - assert.exception(function () { - call.callArgOnWith(2, thisObj); - }, {message: "Expected argument at position 2 to be a Function, but was number"}); + assert.exception( + function() { + call.callArgOnWith(2, thisObj); + }, + { message: "Expected argument at position 2 to be a Function, but was number" } + ); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var thisObj = { name1: "value1", name2: "value2" }; var call = this.call; - assert.exception(function () { - call.callArgOnWith({}, thisObj); - }, {name: "TypeError"}); + assert.exception( + function() { + call.callArgOnWith({}, thisObj); + }, + { name: "TypeError" } + ); }); }); - describe(".callback", function () { - it("it should be a reference for the callback", function () { + describe(".callback", function() { + it("it should be a reference for the callback", function() { var spy = sinonSpy(); - var callback1 = function () { return; }; - var callback2 = function () { return; }; + var callback1 = function() { + return; + }; + var callback2 = function() { + return; + }; spy(1, 2, 3, callback1); assert.equals(spy.getCall(0).callback, callback1); @@ -477,8 +549,8 @@ describe("sinonSpy.call", function () { }); }); - describe(".lastArg", function () { - it("should be the last argument from the call", function () { + describe(".lastArg", function() { + it("should be the last argument from the call", function() { var spy = sinonSpy(); spy(41, 42, 43); @@ -495,10 +567,10 @@ describe("sinonSpy.call", function () { }); }); - describe("call.yieldTest", function () { + describe("call.yieldTest", function() { beforeEach(spyCallCallSetup); - it("invokes only argument as callback", function () { + it("invokes only argument as callback", function() { var callback = sinonSpy(); this.args.push(callback); @@ -508,11 +580,11 @@ describe("sinonSpy.call", function () { assert.equals(callback.args[0].length, 0); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var call = this.call; assert.exception( - function () { + function() { call.yield(); }, { @@ -521,23 +593,22 @@ describe("sinonSpy.call", function () { ); }); - it("includes stub name and actual arguments in error", function () { + it("includes stub name and actual arguments in error", function() { this.proxy.displayName = "somethingAwesome"; this.args.push(23, 42); var call = this.call; assert.exception( - function () { + function() { call.yield(); }, { - message: "somethingAwesome cannot yield since no callback was passed. " - + "Received [23, 42]" + message: "somethingAwesome cannot yield since no callback was passed. " + "Received [23, 42]" } ); }); - it("invokes last argument as callback", function () { + it("invokes last argument as callback", function() { var spy = sinonSpy(); this.args.push(24, {}, spy); @@ -547,7 +618,7 @@ describe("sinonSpy.call", function () { assert.equals(spy.args[0].length, 0); }); - it("invokes first of two callbacks", function () { + it("invokes first of two callbacks", function() { var spy = sinonSpy(); var spy2 = sinonSpy(); this.args.push(24, {}, spy, spy2); @@ -558,7 +629,7 @@ describe("sinonSpy.call", function () { assert.isFalse(spy2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var spy = sinonSpy(); this.args.push(spy); @@ -568,8 +639,8 @@ describe("sinonSpy.call", function () { assert(spy.calledWith(obj, "Crazy")); }); - it("returns callbacks return value", function () { - var spy = sinonSpy(function () { + it("returns callbacks return value", function() { + var spy = sinonSpy(function() { return "useful value"; }); this.args.push(24, {}, spy); @@ -579,32 +650,39 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if callback throws", function () { - this.args.push(function () { + it("throws if callback throws", function() { + this.args.push(function() { throw new Error("d'oh!"); }); var call = this.call; - assert.exception(function () { + assert.exception(function() { call.yield(); }); }); }); - describe("call.invokeCallback", function () { - - it("is alias for yield", function () { - var call = sinonSpyCall(function () { return; }, {}, [], null, null, 0); + describe("call.invokeCallback", function() { + it("is alias for yield", function() { + var call = sinonSpyCall( + function() { + return; + }, + {}, + [], + null, + null, + 0 + ); assert.same(call.yield, call.invokeCallback); }); - }); - describe("call.yieldOnTest", function () { + describe("call.yieldOnTest", function() { beforeEach(spyCallCallSetup); - it("invokes only argument as callback", function () { + it("invokes only argument as callback", function() { var callback = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; this.args.push(callback); @@ -616,12 +694,12 @@ describe("sinonSpy.call", function () { assert.equals(callback.args[0].length, 0); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var call = this.call; var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { call.yieldOn(thisObj); }, { @@ -630,24 +708,23 @@ describe("sinonSpy.call", function () { ); }); - it("includes stub name and actual arguments in error", function () { + it("includes stub name and actual arguments in error", function() { this.proxy.displayName = "somethingAwesome"; this.args.push(23, 42); var call = this.call; var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { call.yieldOn(thisObj); }, { - message: "somethingAwesome cannot yield since no callback was passed. " + - "Received [23, 42]" + message: "somethingAwesome cannot yield since no callback was passed. " + "Received [23, 42]" } ); }); - it("invokes last argument as callback", function () { + it("invokes last argument as callback", function() { var spy = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; this.args.push(24, {}, spy); @@ -659,7 +736,7 @@ describe("sinonSpy.call", function () { assert(spy.calledOn(thisObj)); }); - it("invokes first of two callbacks", function () { + it("invokes first of two callbacks", function() { var spy = sinonSpy(); var spy2 = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -672,7 +749,7 @@ describe("sinonSpy.call", function () { assert.isFalse(spy2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var spy = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -684,8 +761,8 @@ describe("sinonSpy.call", function () { assert(spy.calledOn(thisObj)); }); - it("returns callbacks return value", function () { - var spy = sinonSpy(function () { + it("returns callbacks return value", function() { + var spy = sinonSpy(function() { return "useful value"; }); var thisObj = { name1: "value1", name2: "value2" }; @@ -696,23 +773,23 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if callback throws", function () { - this.args.push(function () { + it("throws if callback throws", function() { + this.args.push(function() { throw new Error("d'oh!"); }); var call = this.call; var thisObj = { name1: "value1", name2: "value2" }; - assert.exception(function () { + assert.exception(function() { call.yieldOn(thisObj); }); }); }); - describe("call.yieldTo", function () { + describe("call.yieldTo", function() { beforeEach(spyCallCallSetup); - it("invokes only argument as callback", function () { + it("invokes only argument as callback", function() { var callback = sinonSpy(); this.args.push({ success: callback @@ -724,11 +801,11 @@ describe("sinonSpy.call", function () { assert.equals(callback.args[0].length, 0); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var call = this.call; assert.exception( - function () { + function() { call.yieldTo("success"); }, { @@ -737,23 +814,24 @@ describe("sinonSpy.call", function () { ); }); - it("includes stub name and actual arguments in error", function () { + it("includes stub name and actual arguments in error", function() { this.proxy.displayName = "somethingAwesome"; this.args.push(23, 42); var call = this.call; assert.exception( - function () { + function() { call.yieldTo("success"); }, { - message: "somethingAwesome cannot yield to 'success' since no callback was passed. " - + "Received [23, 42]" + message: + "somethingAwesome cannot yield to 'success' since no callback was passed. " + + "Received [23, 42]" } ); }); - it("invokes property on last argument as callback", function () { + it("invokes property on last argument as callback", function() { var spy = sinonSpy(); this.args.push(24, {}, { success: spy }); @@ -763,7 +841,7 @@ describe("sinonSpy.call", function () { assert.equals(spy.args[0].length, 0); }); - it("invokes first of two possible callbacks", function () { + it("invokes first of two possible callbacks", function() { var spy = sinonSpy(); var spy2 = sinonSpy(); this.args.push(24, {}, { error: spy }, { error: spy2 }); @@ -774,7 +852,7 @@ describe("sinonSpy.call", function () { assert.isFalse(spy2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var spy = sinonSpy(); this.args.push({ success: spy }); @@ -784,8 +862,8 @@ describe("sinonSpy.call", function () { assert(spy.calledWith(obj, "Crazy")); }); - it("returns callbacks return value", function () { - var spy = sinonSpy(function () { + it("returns callbacks return value", function() { + var spy = sinonSpy(function() { return "useful value"; }); this.args.push(24, {}, { success: spy }); @@ -795,24 +873,24 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { this.args.push({ - success: function () { + success: function() { throw new Error("d'oh!"); } }); var call = this.call; - assert.exception(function () { + assert.exception(function() { call.yieldTo("success"); }); }); }); - describe("call.yieldToOn", function () { + describe("call.yieldToOn", function() { beforeEach(spyCallCallSetup); - it("invokes only argument as callback", function () { + it("invokes only argument as callback", function() { var callback = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; this.args.push({ @@ -826,12 +904,12 @@ describe("sinonSpy.call", function () { assert(callback.calledOn(thisObj)); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var call = this.call; var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { call.yieldToOn("success", thisObj); }, { @@ -840,13 +918,13 @@ describe("sinonSpy.call", function () { ); }); - it("throws understandable error if symbol prop is not found", function () { + it("throws understandable error if symbol prop is not found", function() { if (typeof Symbol === "function") { var call = this.call; var symbol = Symbol(); assert.exception( - function () { + function() { call.yieldToOn(symbol, {}); }, { @@ -856,24 +934,25 @@ describe("sinonSpy.call", function () { } }); - it("includes stub name and actual arguments in error", function () { + it("includes stub name and actual arguments in error", function() { this.proxy.displayName = "somethingAwesome"; this.args.push(23, 42); var call = this.call; var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { call.yieldToOn("success", thisObj); }, { - message: "somethingAwesome cannot yield to 'success' since no callback was passed. " - + "Received [23, 42]" + message: + "somethingAwesome cannot yield to 'success' since no callback was passed. " + + "Received [23, 42]" } ); }); - it("invokes property on last argument as callback", function () { + it("invokes property on last argument as callback", function() { var spy = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; this.args.push(24, {}, { success: spy }); @@ -885,7 +964,7 @@ describe("sinonSpy.call", function () { assert.equals(spy.args[0].length, 0); }); - it("invokes first of two possible callbacks", function () { + it("invokes first of two possible callbacks", function() { var spy = sinonSpy(); var spy2 = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -898,7 +977,7 @@ describe("sinonSpy.call", function () { assert.isFalse(spy2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var spy = sinonSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -910,8 +989,8 @@ describe("sinonSpy.call", function () { assert(spy.calledOn(thisObj)); }); - it("returns callbacks return value", function () { - var spy = sinonSpy(function () { + it("returns callbacks return value", function() { + var spy = sinonSpy(function() { return "useful value"; }); var thisObj = { name1: "value1", name2: "value2" }; @@ -922,104 +1001,160 @@ describe("sinonSpy.call", function () { assert.equals(returnValue, "useful value"); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { this.args.push({ - success: function () { + success: function() { throw new Error("d'oh!"); } }); var call = this.call; var thisObj = { name1: "value1", name2: "value2" }; - assert.exception(function () { + assert.exception(function() { call.yieldToOn("success", thisObj); }); }); }); - describe("call.toString", function () { - afterEach(function () { + describe("call.toString", function() { + afterEach(function() { if (this.format) { this.format.restore(); } }); - it("includes spy name", function () { + it("includes spy name", function() { var object = { doIt: sinonSpy() }; object.doIt(); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt()"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt()" + ); }); - it("includes single argument", function () { + it("includes single argument", function() { var object = { doIt: sinonSpy() }; object.doIt(42); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt(42)"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt(42)" + ); }); - it("includes all arguments", function () { + it("includes all arguments", function() { var object = { doIt: sinonSpy() }; object.doIt(42, "Hey"); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt(42, Hey)"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt(42, Hey)" + ); }); - it("includes explicit return value", function () { + it("includes explicit return value", function() { var object = { doIt: sinonStub().returns(42) }; object.doIt(42, "Hey"); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt(42, Hey) => 42"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt(42, Hey) => 42" + ); }); - it("includes empty string return value", function () { + it("includes empty string return value", function() { var object = { doIt: sinonStub().returns("") }; object.doIt(42, "Hey"); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt(42, Hey) => (empty string)"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt(42, Hey) => (empty string)" + ); }); - it("includes exception", function () { + it("includes exception", function() { var object = { doIt: sinonStub().throws("TypeError") }; - assert.exception(function () { + assert.exception(function() { object.doIt(); }); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt() !TypeError"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt() !TypeError" + ); }); - it("includes exception message if any", function () { + it("includes exception message if any", function() { var object = { doIt: sinonStub().throws("TypeError", "Oh noes!") }; - assert.exception(function () { + assert.exception(function() { object.doIt(); }); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt() !TypeError(Oh noes!)"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt() !TypeError(Oh noes!)" + ); }); // these tests are ensuring that call.toString is handled by sinonFormat - it("formats arguments with sinonFormat", function () { + it("formats arguments with sinonFormat", function() { var object = { doIt: sinonSpy() }; object.doIt(42); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt(42)"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt(42)" + ); }); - it("formats return value with sinonFormat", function () { + it("formats return value with sinonFormat", function() { var object = { doIt: sinonStub().returns(42) }; object.doIt(); - assert.equals(object.doIt.getCall(0).toString().replace(/ at.*/g, ""), "doIt() => 42"); + assert.equals( + object.doIt + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "doIt() => 42" + ); }); // https://github.com/sinonjs/sinon/issues/1066 /* eslint-disable consistent-return */ - it("does not throw when the call stack is empty", function (done) { - if (!global.Promise) { this.skip(); } + it("does not throw when the call stack is empty", function(done) { + if (!global.Promise) { + this.skip(); + } var stub1 = sinonStub().resolves(1); var stub2 = sinonStub().returns(1); @@ -1029,87 +1164,103 @@ describe("sinonSpy.call", function () { } run() - .then(function () { - assert.equals(stub2.getCall(0).toString().replace(/ at.*/g, ""), "stub(1) => 1"); + .then(function() { + assert.equals( + stub2 + .getCall(0) + .toString() + .replace(/ at.*/g, ""), + "stub(1) => 1" + ); done(); }) - .catch( done ); + .catch(done); }); /* eslint-enable consistent-return */ }); - describe("constructor", function () { - beforeEach(function () { - this.CustomConstructor = function () { return; }; + describe("constructor", function() { + beforeEach(function() { + this.CustomConstructor = function() { + return; + }; this.customPrototype = this.CustomConstructor.prototype; sinonSpy(this, "CustomConstructor"); }); - it("creates original object", function () { + it("creates original object", function() { var myInstance = new this.CustomConstructor(); assert(this.customPrototype.isPrototypeOf(myInstance)); }); - it("does not interfere with instanceof", function () { + it("does not interfere with instanceof", function() { var myInstance = new this.CustomConstructor(); assert(myInstance instanceof this.CustomConstructor); }); - it("records usage", function () { + it("records usage", function() { var myInstance = new this.CustomConstructor(); // eslint-disable-line no-unused-vars assert(this.CustomConstructor.called); }); }); - describe("functions", function () { - it("throws if spying on non-existent property", function () { + describe("functions", function() { + it("throws if spying on non-existent property", function() { var myObj = {}; - assert.exception(function () { + assert.exception(function() { sinonSpy(myObj, "ouch"); }); refute.defined(myObj.ouch); }); - it("throws if spying on non-existent object", function () { - assert.exception(function () { + it("throws if spying on non-existent object", function() { + assert.exception(function() { sinonSpy(undefined, "ouch"); }); }); - it("haves toString method", function () { - var obj = { meth: function () { return; } }; + it("haves toString method", function() { + var obj = { + meth: function() { + return; + } + }; sinonSpy(obj, "meth"); assert.equals(obj.meth.toString(), "meth"); }); - it("toString should say 'spy' when unable to infer name", function () { + it("toString should say 'spy' when unable to infer name", function() { var spy = sinonSpy(); assert.equals(spy.toString(), "spy"); }); - it("toString should report name of spied function", function () { - function myTestFunc() { return; } + it("toString should report name of spied function", function() { + function myTestFunc() { + return; + } var spy = sinonSpy(myTestFunc); assert.equals(spy.toString(), "myTestFunc"); }); - it("toString should prefer displayName property if available", function () { - function myTestFunc() { return; } + it("toString should prefer displayName property if available", function() { + function myTestFunc() { + return; + } myTestFunc.displayName = "My custom method"; var spy = sinonSpy(myTestFunc); assert.equals(spy.toString(), "My custom method"); }); - it("toString should prefer property name if possible", function () { + it("toString should prefer property name if possible", function() { var obj = {}; obj.meth = sinonSpy(); obj.meth(); @@ -1118,7 +1269,7 @@ describe("sinonSpy.call", function () { }); }); - describe(".reset", function () { + describe(".reset", function() { function assertReset(spy) { assert(!spy.called); assert(!spy.calledOnce); @@ -1132,7 +1283,7 @@ describe("sinonSpy.call", function () { assert.isNull(spy.lastCall); } - it("resets spy state", function () { + it("resets spy state", function() { var spy = sinonSpy(); spy(); @@ -1141,7 +1292,7 @@ describe("sinonSpy.call", function () { assertReset(spy); }); - it("resets call order state", function () { + it("resets call order state", function() { var spies = [sinonSpy(), sinonSpy()]; spies[0](); spies[1](); @@ -1151,7 +1302,7 @@ describe("sinonSpy.call", function () { assert(!spies[0].calledBefore(spies[1])); }); - it("resets fakes returned by withArgs", function () { + it("resets fakes returned by withArgs", function() { var spy = sinonSpy(); var fakeA = spy.withArgs("a"); var fakeB = spy.withArgs("b"); @@ -1168,21 +1319,21 @@ describe("sinonSpy.call", function () { }); }); - describe(".withArgs", function () { - it("defines withArgs method", function () { + describe(".withArgs", function() { + it("defines withArgs method", function() { var spy = sinonSpy(); assert.isFunction(spy.withArgs); }); - it("records single call", function () { + it("records single call", function() { var spy = sinonSpy().withArgs(1); spy(1); assert.equals(spy.callCount, 1); }); - it("records non-matching call on original spy", function () { + it("records non-matching call on original spy", function() { var spy = sinonSpy(); var argSpy = spy.withArgs(1); spy(1); @@ -1192,7 +1343,7 @@ describe("sinonSpy.call", function () { assert.equals(argSpy.callCount, 1); }); - it("records non-matching call with several arguments separately", function () { + it("records non-matching call with several arguments separately", function() { var spy = sinonSpy(); var argSpy = spy.withArgs(1, "str", {}); spy(1); @@ -1202,7 +1353,7 @@ describe("sinonSpy.call", function () { assert.equals(argSpy.callCount, 1); }); - it("records for partial argument match", function () { + it("records for partial argument match", function() { var spy = sinonSpy(); var argSpy = spy.withArgs(1, "str", {}); spy(1); @@ -1213,18 +1364,18 @@ describe("sinonSpy.call", function () { assert.equals(argSpy.callCount, 2); }); - it("records filtered spy when original throws", function () { - var spy = sinonSpy(function () { + it("records filtered spy when original throws", function() { + var spy = sinonSpy(function() { throw new Error("Oops"); }); var argSpy = spy.withArgs({}, []); - assert.exception(function () { + assert.exception(function() { spy(1); }); - assert.exception(function () { + assert.exception(function() { spy({}, []); }); @@ -1232,7 +1383,7 @@ describe("sinonSpy.call", function () { assert.equals(argSpy.callCount, 1); }); - it("returns existing override for arguments", function () { + it("returns existing override for arguments", function() { var spy = sinonSpy(); var argSpy = spy.withArgs({}, []); var another = spy.withArgs({}, []); @@ -1246,7 +1397,7 @@ describe("sinonSpy.call", function () { assert.equals(spy.withArgs({}, []).callCount, 2); }); - it("chains withArgs calls on original spy", function () { + it("chains withArgs calls on original spy", function() { var spy = sinonSpy(); var numArgSpy = spy.withArgs({}, []).withArgs(3); spy(); @@ -1258,7 +1409,7 @@ describe("sinonSpy.call", function () { assert.equals(spy.withArgs({}, []).callCount, 1); }); - it("initializes filtered spy with callCount", function () { + it("initializes filtered spy with callCount", function() { var spy = sinonSpy(); spy("a"); spy("b"); @@ -1282,7 +1433,7 @@ describe("sinonSpy.call", function () { assert(argSpy3.calledThrice); }); - it("initializes filtered spy with first, second, third and last call", function () { + it("initializes filtered spy with first, second, third and last call", function() { var spy = sinonSpy(); spy("a", 1); spy("b", 2); @@ -1300,7 +1451,7 @@ describe("sinonSpy.call", function () { assert(argSpy2.lastCall.calledWithExactly("b", 4)); }); - it("initializes filtered spy with arguments", function () { + it("initializes filtered spy with arguments", function() { var spy = sinonSpy(); spy("a"); spy("b"); @@ -1314,7 +1465,7 @@ describe("sinonSpy.call", function () { assert(argSpy2.getCall(1).calledWithExactly("b", "c", "d")); }); - it("initializes filtered spy with thisValues", function () { + it("initializes filtered spy with thisValues", function() { var spy = sinonSpy(); var thisValue1 = {}; var thisValue2 = {}; @@ -1331,8 +1482,8 @@ describe("sinonSpy.call", function () { assert(argSpy2.getCall(1).calledOn(thisValue3)); }); - it("initializes filtered spy with return values", function () { - var spy = sinonSpy(function (value) { + it("initializes filtered spy with return values", function() { + var spy = sinonSpy(function(value) { return value; }); spy("a"); @@ -1347,7 +1498,7 @@ describe("sinonSpy.call", function () { assert(argSpy2.getCall(1).returned("b")); }); - it("initializes filtered spy with call order", function () { + it("initializes filtered spy with call order", function() { var spy = sinonSpy(); spy("a"); spy("b"); @@ -1360,20 +1511,20 @@ describe("sinonSpy.call", function () { assert(argSpy2.getCall(1).calledAfter(argSpy1.getCall(0))); }); - it("initializes filtered spy with exceptions", function () { - var spy = sinonSpy(function (x, y) { + it("initializes filtered spy with exceptions", function() { + var spy = sinonSpy(function(x, y) { var error = new Error(); error.name = y; throw error; }); - assert.exception(function () { + assert.exception(function() { spy("a", "1"); }); - assert.exception(function () { + assert.exception(function() { spy("b", "2"); }); - assert.exception(function () { + assert.exception(function() { spy("b", "3"); }); @@ -1386,14 +1537,18 @@ describe("sinonSpy.call", function () { }); }); - describe(".printf", function () { - describe("name", function () { - it("named", function () { - var named = sinonSpy(function cool() { return; }); + describe(".printf", function() { + describe("name", function() { + it("named", function() { + var named = sinonSpy(function cool() { + return; + }); assert.equals(named.printf("%n"), "cool"); }); - it("anon", function () { - var anon = sinonSpy(function () { return; }); + it("anon", function() { + var anon = sinonSpy(function() { + return; + }); assert.equals(anon.printf("%n"), "spy"); var noFn = sinonSpy(); @@ -1401,11 +1556,11 @@ describe("sinonSpy.call", function () { }); }); - it("count", function () { + it("count", function() { // Throwing just to make sure it has no effect. var spy = sinonSpy(sinonStub().throws()); function call() { - assert.exception(function () { + assert.exception(function() { spy(); }); } @@ -1420,8 +1575,8 @@ describe("sinonSpy.call", function () { assert.equals(spy.printf("%c"), "4 times"); }); - describe("calls", function () { - it("oneLine", function () { + describe("calls", function() { + it("oneLine", function() { function verify(arg, expected) { var spy = sinonSpy(); spy(arg); @@ -1436,11 +1591,11 @@ describe("sinonSpy.call", function () { verify(-1, "spy(-1)"); verify(-1.1, "spy(-1.1)"); verify(Infinity, "spy(Infinity)"); - verify(["a"], "spy([\"a\"])"); - verify({ a: "a" }, "spy({ a: \"a\" })"); + verify(["a"], 'spy(["a"])'); + verify({ a: "a" }, 'spy({ a: "a" })'); }); - it("multiline", function () { + it("multiline", function() { var str = "spy\ntest"; var spy = sinonSpy(); @@ -1448,10 +1603,10 @@ describe("sinonSpy.call", function () { spy(str); spy(str); - assert.equals(spy.printf("%C").replace(/ at.*/g, ""), - "\n spy(" + str + ")" + - "\n\n spy(" + str + ")" + - "\n\n spy(" + str + ")"); + assert.equals( + spy.printf("%C").replace(/ at.*/g, ""), + "\n spy(" + str + ")" + "\n\n spy(" + str + ")" + "\n\n spy(" + str + ")" + ); spy.resetHistory(); @@ -1459,14 +1614,14 @@ describe("sinonSpy.call", function () { spy("spy\ntest"); spy("spy\ntest"); - assert.equals(spy.printf("%C").replace(/ at.*/g, ""), - "\n spy(test)" + - "\n spy(" + str + ")" + - "\n\n spy(" + str + ")"); + assert.equals( + spy.printf("%C").replace(/ at.*/g, ""), + "\n spy(test)" + "\n spy(" + str + ")" + "\n\n spy(" + str + ")" + ); }); }); - it("thisValues", function () { + it("thisValues", function() { var spy = sinonSpy(); spy(); assert.equals(spy.printf("%t"), "undefined"); @@ -1476,13 +1631,13 @@ describe("sinonSpy.call", function () { assert.equals(spy.printf("%t"), "true"); }); - it("unmatched", function () { + it("unmatched", function() { var spy = sinonSpy(); assert.equals(spy.printf("%λ"), "%λ"); }); - it("*", function () { + it("*", function() { var spy = sinonSpy(); assert.equals( @@ -1492,32 +1647,40 @@ describe("sinonSpy.call", function () { assert.equals(spy.printf("%*", "a", "b", "c"), "a, b, c"); }); - describe("arguments", function () { - it("no calls", function () { + describe("arguments", function() { + it("no calls", function() { var spy = sinonSpy(); assert.equals(spy.printf("%D"), ""); }); - it("single call with arguments", function () { + it("single call with arguments", function() { var spy = sinonSpy(); spy(1, "a", true, false, [], {}, null, undefined); assert.equals( spy.printf("%D"), - "\n" + color.red("1") + - "\n" + color.red("a") + - "\n" + color.red("true") + - "\n" + color.red("false") + - "\n" + color.red("[]") + - "\n" + color.red("{ }") + - "\n" + color.red("null") + - "\n" + color.red("undefined") + "\n" + + color.red("1") + + "\n" + + color.red("a") + + "\n" + + color.red("true") + + "\n" + + color.red("false") + + "\n" + + color.red("[]") + + "\n" + + color.red("{ }") + + "\n" + + color.red("null") + + "\n" + + color.red("undefined") ); }); - it("single call without arguments", function () { + it("single call without arguments", function() { var spy = sinonSpy(); spy(); @@ -1525,7 +1688,7 @@ describe("sinonSpy.call", function () { assert.equals(spy.printf("%D"), ""); }); - it("multiple calls with arguments", function () { + it("multiple calls with arguments", function() { var spy = sinonSpy(); spy(1, "a", true); @@ -1535,20 +1698,28 @@ describe("sinonSpy.call", function () { assert.equals( spy.printf("%D"), "\nCall 1:" + - "\n" + color.red("1") + - "\n" + color.red("a") + - "\n" + color.red("true") + - "\nCall 2:" + - "\n" + color.red("false") + - "\n" + color.red("[]") + - "\n" + color.red("{ }") + - "\nCall 3:" + - "\n" + color.red("null") + - "\n" + color.red("undefined") + "\n" + + color.red("1") + + "\n" + + color.red("a") + + "\n" + + color.red("true") + + "\nCall 2:" + + "\n" + + color.red("false") + + "\n" + + color.red("[]") + + "\n" + + color.red("{ }") + + "\nCall 3:" + + "\n" + + color.red("null") + + "\n" + + color.red("undefined") ); }); - it("multiple calls without arguments", function () { + it("multiple calls without arguments", function() { var spy = sinonSpy(); spy(); @@ -1560,7 +1731,7 @@ describe("sinonSpy.call", function () { }); }); - it("captures a stack trace", function () { + it("captures a stack trace", function() { var spy = sinonSpy(); spy(); assert.isString(spy.getCall(0).stack); diff --git a/test/es2015/a-function-module.mjs b/test/es2015/a-function-module.mjs index 8883e9ed8..9fd7724b3 100644 --- a/test/es2015/a-function-module.mjs +++ b/test/es2015/a-function-module.mjs @@ -1 +1,3 @@ -export default function () { return 42; } +export default function() { + return 42; +} diff --git a/test/es2015/a-module-with-default.mjs b/test/es2015/a-module-with-default.mjs index eb591ba30..23b2fe701 100644 --- a/test/es2015/a-module-with-default.mjs +++ b/test/es2015/a-module-with-default.mjs @@ -1,3 +1,5 @@ export default { - anExport() { return 42; } + anExport() { + return 42; + } }; diff --git a/test/es2015/a-module-with-to-string-tag.mjs b/test/es2015/a-module-with-to-string-tag.mjs index e3b3da0d2..a15e19664 100644 --- a/test/es2015/a-module-with-to-string-tag.mjs +++ b/test/es2015/a-module-with-to-string-tag.mjs @@ -1,4 +1,6 @@ export default { [Symbol.toStringTag]: "Module", - anExport() { return 42; } + anExport() { + return 42; + } }; diff --git a/test/es2015/a-module.mjs b/test/es2015/a-module.mjs index f2f654fa1..f4ba73627 100644 --- a/test/es2015/a-module.mjs +++ b/test/es2015/a-module.mjs @@ -1 +1,3 @@ -export function anExport() { return 42; } +export function anExport() { + return 42; +} diff --git a/test/es2015/check-esm-bundle-is-runnable.js b/test/es2015/check-esm-bundle-is-runnable.js index 41000afb5..8ce866075 100644 --- a/test/es2015/check-esm-bundle-is-runnable.js +++ b/test/es2015/check-esm-bundle-is-runnable.js @@ -49,12 +49,12 @@ async function evaluatePageContent() { process.exit(1); } - page.on("error", function (err) { + page.on("error", function(err) { throw err; }); // our "assertion framework" :) - page.on("console", function (msg) { + page.on("console", function(msg) { var text = msg.text(); if (text.startsWith("sinon-result:works")) { diff --git a/test/es2015/module-support-assessment-test.mjs b/test/es2015/module-support-assessment-test.mjs index b1abd77a0..8f1b50388 100644 --- a/test/es2015/module-support-assessment-test.mjs +++ b/test/es2015/module-support-assessment-test.mjs @@ -7,33 +7,33 @@ import aModuleWithDefaultExport from "./a-module-with-default"; // Usually one would import the default module, but one can make a form of wrapper like this /* eslint-disable no-unused-vars */ import functionModule, * as functionModuleAlternative from "./a-function-module"; -const {assert, refute} = referee; +const { assert, refute } = referee; function createTestSuite(action) { var stub; var errorRegEx = /TypeError: ES Modules cannot be (stubbed|spied)/; - describe("sinon." + action + "()", function () { - - afterEach(function () { - if (stub && stub.restore) { stub.restore(); } + describe("sinon." + action + "()", function() { + afterEach(function() { + if (stub && stub.restore) { + stub.restore(); + } }); - describe("Modules with objects as their default export", function () { - - it("should NOT result in error", function () { - refute.exception(function () { + describe("Modules with objects as their default export", function() { + it("should NOT result in error", function() { + refute.exception(function() { stub = sinon[action](aModuleWithDefaultExport, "anExport"); }); }); - it("should NOT result in error with a custom toStringTag", function () { - refute.exception(function () { + it("should NOT result in error with a custom toStringTag", function() { + refute.exception(function() { stub = sinon[action](aModuleWithToStringTag, "anExport"); }); }); - it("should spy/stub an exported function", function () { + it("should spy/stub an exported function", function() { stub = sinon[action](aModuleWithDefaultExport, "anExport"); aModuleWithDefaultExport.anExport(); aModuleWithDefaultExport.anExport(); @@ -41,17 +41,17 @@ function createTestSuite(action) { }); }); - describe("Modules without default export", function () { - it("should give a proper error message", function () { - assert.exception(function () { + describe("Modules without default export", function() { + it("should give a proper error message", function() { + assert.exception(function() { sinon[action](aModule, "anExport"); }, errorRegEx); }); }); - describe("Modules that exports a function as their default export", function () { - it("should not be possible to spy/stub the default export using a wrapper for the exports", function () { - assert.exception(function () { + describe("Modules that exports a function as their default export", function() { + it("should not be possible to spy/stub the default export using a wrapper for the exports", function() { + assert.exception(function() { stub = sinon[action](functionModuleAlternative, "anExport"); }, errorRegEx); }); diff --git a/test/extend-test.js b/test/extend-test.js index 7d0e3d4a8..7f5aa8bb9 100644 --- a/test/extend-test.js +++ b/test/extend-test.js @@ -4,8 +4,8 @@ var referee = require("@sinonjs/referee"); var extend = require("../lib/sinon/util/core/extend"); var assert = referee.assert; -describe("extend", function () { - it("should return unaltered target when only one argument", function () { +describe("extend", function() { + it("should return unaltered target when only one argument", function() { var target = { hello: "world" }; extend(target); @@ -13,7 +13,7 @@ describe("extend", function () { assert.equals(target, { hello: "world" }); }); - it("should copy all (own) properties into first argument, from all subsequent arguments", function () { + it("should copy all (own) properties into first argument, from all subsequent arguments", function() { var target = { hello: "world" }; extend(target, { a: "a" }, { b: "b" }); @@ -23,15 +23,15 @@ describe("extend", function () { assert.equals(target.b, "b"); }); - it("should copy toString method into target", function () { + it("should copy toString method into target", function() { var target = { hello: "world", - toString: function () { + toString: function() { return "hello world"; } }; var source = { - toString: function () { + toString: function() { return "hello source"; } }; @@ -41,7 +41,7 @@ describe("extend", function () { assert.same(target.toString, source.toString); }); - it("must copy the last occurring property into the target", function () { + it("must copy the last occurring property into the target", function() { var target = { a: 0, b: 0, c: 0, d: 0 }; var source1 = { a: 1, b: 1, c: 1 }; var source2 = { a: 2, b: 2 }; @@ -55,7 +55,7 @@ describe("extend", function () { assert.equals(target.d, 0); }); - it("copies all properties", function () { + it("copies all properties", function() { var object1 = { prop1: null, prop2: false diff --git a/test/fake-test.js b/test/fake-test.js index f0cc2d2c2..0fdeba2a1 100644 --- a/test/fake-test.js +++ b/test/fake-test.js @@ -22,14 +22,16 @@ referee.add("isProxy", { }); function verifyProxy(func, argument) { - it("should return a Sinon proxy", function () { + it("should return a Sinon proxy", function() { var actual = argument ? func(argument) : func(); assert.isProxy(actual); }); } -function noop() { return; } +function noop() { + return; +} function requirePromiseSupport() { if (typeof Promise !== "function") { @@ -39,9 +41,9 @@ function requirePromiseSupport() { var hasFunctionNameSupport = noop.name === "noop"; -describe("fake", function () { - describe("module", function () { - it("should return a unary Function named 'fake'", function () { +describe("fake", function() { + describe("module", function() { + it("should return a unary Function named 'fake'", function() { assert.equals(fake.length, 1); if (hasFunctionNameSupport) { assert.equals(fake.name, "fake"); @@ -49,11 +51,15 @@ describe("fake", function () { }); }); - describe("when passed a Function", function () { - verifyProxy(fake, function () { return; }); + describe("when passed a Function", function() { + verifyProxy(fake, function() { + return; + }); - it("should keep the `this` context of the wrapped function", function () { - function method() { return this.foo; } + it("should keep the `this` context of the wrapped function", function() { + function method() { + return this.foo; + } var o = { foo: 42 }; var fakeMethod = fake(method); @@ -64,25 +70,29 @@ describe("fake", function () { }); }); - describe("when passed no value", function () { + describe("when passed no value", function() { verifyProxy(fake); }); - it("should reject non-Function argument", function () { + it("should reject non-Function argument", function() { var nonFuncs = ["", 123, new Date(), {}, false, undefined, true, null]; - nonFuncs.forEach(function (nf) { - assert.exception(function () { + nonFuncs.forEach(function(nf) { + assert.exception(function() { fake(nf); }); }); }); - describe(".callback", function () { - it("it should be a reference for the callback in the last call", function () { + describe(".callback", function() { + it("it should be a reference for the callback in the last call", function() { var f = fake(); - var callback1 = function () { return; }; - var callback2 = function () { return; }; + var callback1 = function() { + return; + }; + var callback2 = function() { + return; + }; f(1, 2, 3, callback1); assert.equals(f.callback, callback1); @@ -95,8 +105,8 @@ describe("fake", function () { }); }); - describe(".displayName", function () { - it("should be 'fake'", function () { + describe(".displayName", function() { + it("should be 'fake'", function() { var fakes = [ fake(), fake.returns(42), @@ -107,22 +117,22 @@ describe("fake", function () { fake.yieldsAsync(42) ]; - fakes.forEach(function (f) { + fakes.forEach(function(f) { assert.equals(f.displayName, "fake"); }); }); }); - describe(".id", function () { - it("should start with 'fake#'", function () { + describe(".id", function() { + it("should start with 'fake#'", function() { for (var i = 0; i < 100; i++) { assert.isTrue(fake().id.indexOf("fake#") === 0); } }); }); - describe(".lastArg", function () { - it("should be the last argument from the last call", function () { + describe(".lastArg", function() { + it("should be the last argument from the last call", function() { var f = fake(); f(41, 42, 43); assert.equals(f.lastArg, 43); @@ -138,8 +148,8 @@ describe("fake", function () { }); }); - describe(".returns", function () { - it("should return a function that returns the argument", function () { + describe(".returns", function() { + it("should return a function that returns the argument", function() { var expected = 42; var myFake = fake.returns(expected); var actual = myFake(); @@ -150,12 +160,12 @@ describe("fake", function () { verifyProxy(fake.returns, "42"); }); - describe(".throws", function () { - it("should return a function that throws an Error, that is the argument", function () { + describe(".throws", function() { + it("should return a function that throws an Error, that is the argument", function() { var expectedMessage = "42"; var myFake = fake.throws(expectedMessage); - assert.exception(function () { + assert.exception(function() { myFake(); }); @@ -170,7 +180,7 @@ describe("fake", function () { verifyProxy(fake.throws, "42"); - it("should return the same error type as it is passed", function () { + it("should return the same error type as it is passed", function() { var expected = new TypeError("hello sailor"); var myFake = fake.throws(expected); @@ -183,8 +193,8 @@ describe("fake", function () { /* eslint-disable no-restricted-syntax */ }); - describe("when passed a String", function () { - it("should throw an Error", function () { + describe("when passed a String", function() { + it("should throw an Error", function() { var expected = "lorem ipsum"; var myFake = fake.throws(expected); @@ -199,14 +209,14 @@ describe("fake", function () { }); }); - describe(".resolves", function () { + describe(".resolves", function() { before(requirePromiseSupport); - it("should return a function that resolves to the argument", function () { + it("should return a function that resolves to the argument", function() { var expected = 42; var myFake = fake.resolves(expected); - return myFake().then(function (actual) { + return myFake().then(function(actual) { assert.equals(actual, expected); }); }); @@ -214,43 +224,43 @@ describe("fake", function () { verifyProxy(fake.resolves, "42"); }); - describe(".rejects", function () { + describe(".rejects", function() { before(requirePromiseSupport); - it("should return a function that rejects to the argument", function () { + it("should return a function that rejects to the argument", function() { var expectedMessage = "42"; var myFake = fake.rejects(expectedMessage); - return myFake().catch(function (actual) { + return myFake().catch(function(actual) { assert.equals(actual.message, expectedMessage); }); }); verifyProxy(fake.rejects, "42"); - it("should return the same error type as it is passed", function () { + it("should return the same error type as it is passed", function() { var expected = new TypeError("hello world"); var myFake = fake.rejects(expected); - return myFake().catch(function (actual) { + return myFake().catch(function(actual) { assert.isTrue(actual instanceof TypeError); }); }); - it("should reject with an Error when passed a String", function () { + it("should reject with an Error when passed a String", function() { var expected = "lorem ipsum"; var myFake = fake.rejects(expected); - return myFake().catch(function (actual) { + return myFake().catch(function(actual) { assert.isTrue(actual instanceof Error); }); }); }); - describe(".yields", function () { + describe(".yields", function() { verifyProxy(fake.yields, noop, "42", "43"); - it("should call a callback with the provided values", function () { + it("should call a callback with the provided values", function() { var callback = sinon.spy(); var myFake = fake.yields("one", "two", "three"); @@ -260,28 +270,32 @@ describe("fake", function () { sinon.assert.calledWith(callback, "one", "two", "three"); }); - it("should call the last function argument", function () { + it("should call the last function argument", function() { var callback = sinon.spy(); var myFake = fake.yields(); - myFake(function () { return; }, callback); + myFake(function() { + return; + }, callback); sinon.assert.calledOnce(callback); }); - it("should throw if the last argument is not a function", function () { + it("should throw if the last argument is not a function", function() { var myFake = fake.yields(); - assert.exception(function () { - myFake(function () { return; }, "not a function"); + assert.exception(function() { + myFake(function() { + return; + }, "not a function"); }, /TypeError: Expected last argument to be a function/); }); }); - describe(".yieldsAsync", function () { + describe(".yieldsAsync", function() { verifyProxy(fake.yieldsAsync, noop, "42", "43"); - it("should call the callback asynchronously with the provided values", function (done) { + it("should call the callback asynchronously with the provided values", function(done) { var callback = sinon.spy(); var myFake = fake.yieldsAsync("one", "two", "three"); @@ -289,7 +303,7 @@ describe("fake", function () { sinon.assert.notCalled(callback); - setTimeout(function () { + setTimeout(function() { sinon.assert.calledOnce(callback); sinon.assert.calledWith(callback, "one", "two", "three"); @@ -297,26 +311,30 @@ describe("fake", function () { }, 0); }); - it("should call the last function argument", function (done) { + it("should call the last function argument", function(done) { var callback = sinon.spy(); var myFake = fake.yieldsAsync(); - myFake(function () { return; }, callback); + myFake(function() { + return; + }, callback); sinon.assert.notCalled(callback); - setTimeout(function () { + setTimeout(function() { sinon.assert.calledOnce(callback); done(); }, 0); }); - it("should throw if the last argument is not a function", function () { + it("should throw if the last argument is not a function", function() { var myFake = fake.yieldsAsync(); - assert.exception(function () { - myFake(function () { return; }, "not a function"); + assert.exception(function() { + myFake(function() { + return; + }, "not a function"); }, /TypeError: Expected last argument to be a function/); }); }); diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index d0b755320..9c666dad5 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -8,16 +8,16 @@ var refute = referee.refute; var globalXHR = global.XMLHttpRequest; var globalAXO = global.ActiveXObject; -describe("issues", function () { - beforeEach(function () { +describe("issues", function() { + beforeEach(function() { this.sandbox = sinon.createSandbox(); }); - afterEach(function () { + afterEach(function() { this.sandbox.restore(); }); - it("#283", function () { + it("#283", function() { function testSinonFakeTimersWith(interval, ticks) { var clock = sinon.useFakeTimers(); @@ -39,14 +39,14 @@ describe("issues", function () { testSinonFakeTimersWith(1000, 1001); }); - describe("#458", function () { + describe("#458", function() { if (typeof require("fs").readFileSync !== "undefined") { - describe("on node", function () { - it("stub out fs.readFileSync", function () { + describe("on node", function() { + it("stub out fs.readFileSync", function() { var fs = require("fs"); var testCase = this; - refute.exception(function () { + refute.exception(function() { testCase.sandbox.stub(fs, "readFileSync"); }); }); @@ -54,9 +54,9 @@ describe("issues", function () { } }); - describe("#624", function () { + describe("#624", function() { // eslint-disable-next-line mocha/no-skipped-tests - it.skip("useFakeTimers should be idempotent", function () { + it.skip("useFakeTimers should be idempotent", function() { // Issue #624 shows that useFakeTimers is not idempotent when it comes to // using Date.now // This test verifies that it's working, at least for Date.now @@ -73,36 +73,44 @@ describe("issues", function () { }); }); - describe("#852 - createStubInstance on intherited constructors", function () { - it("must not throw error", function () { - var A = function () { return; }; - var B = function () { return; }; + describe("#852 - createStubInstance on intherited constructors", function() { + it("must not throw error", function() { + var A = function() { + return; + }; + var B = function() { + return; + }; B.prototype = Object.create(A.prototype); B.prototype.constructor = A; - refute.exception(function () { + refute.exception(function() { sinon.createStubInstance(B); }); }); }); - describe("#852(2) - createStubInstance should on same constructor", function () { - it("must be idempotent", function () { - var A = function () { return; }; - refute.exception(function () { + describe("#852(2) - createStubInstance should on same constructor", function() { + it("must be idempotent", function() { + var A = function() { + return; + }; + refute.exception(function() { sinon.createStubInstance(A); sinon.createStubInstance(A); }); }); }); - describe("#950 - first execution of a spy as a method renames that spy", function () { - function bob() { return; } + describe("#950 - first execution of a spy as a method renames that spy", function() { + function bob() { + return; + } // IE 11 does not support the function name property if (bob.name) { - it("should not rename spies", function () { + it("should not rename spies", function() { var expectedName = "proxy"; var spy = sinon.spy(bob); @@ -127,8 +135,8 @@ describe("issues", function () { } }); - describe("#1026", function () { - it("should stub `watch` method on any Object", function () { + describe("#1026", function() { + it("should stub `watch` method on any Object", function() { // makes sure that Object.prototype.watch is set back to its old value function restore(oldWatch) { if (oldWatch) { @@ -140,15 +148,21 @@ describe("issues", function () { var oldWatch; - try { // eslint-disable-line no-restricted-syntax + // eslint-disable-next-line no-restricted-syntax + try { oldWatch = Object.prototype.watch; if (typeof Object.prototype.watch !== "function") { - Object.prototype.watch = function rolex() { return; }; // eslint-disable-line no-extend-native + // eslint-disable-next-line no-extend-native + Object.prototype.watch = function rolex() { + return; + }; } var stubbedObject = sinon.stub({ - watch: function () { return; } + watch: function() { + return; + } }); stubbedObject.watch(); @@ -163,8 +177,8 @@ describe("issues", function () { }); }); - describe("#1154", function () { - it("Ensures different matchers will not be tested against each other", function () { + describe("#1154", function() { + it("Ensures different matchers will not be tested against each other", function() { var match = sinon.match; var stub = sinon.stub; var readFile = stub(); @@ -184,18 +198,16 @@ describe("issues", function () { var argsA = match(suffixA); var argsB = match(suffixB); - var firstFake = readFile - .withArgs(argsA); + var firstFake = readFile.withArgs(argsA); - var secondFake = readFile - .withArgs(argsB); + var secondFake = readFile.withArgs(argsB); assert(firstFake !== secondFake); }); }); - describe("#1372 - sandbox.resetHistory", function () { - it("should reset spies", function () { + describe("#1372 - sandbox.resetHistory", function() { + it("should reset spies", function() { var spy = this.sandbox.spy(); spy(); @@ -211,8 +223,8 @@ describe("issues", function () { }); }); - describe("#1398", function () { - it("Call order takes into account both calledBefore and callCount", function () { + describe("#1398", function() { + it("Call order takes into account both calledBefore and callCount", function() { var s1 = sinon.spy(); var s2 = sinon.spy(); @@ -220,14 +232,13 @@ describe("issues", function () { s2(); s1(); - assert.exception(function () { + assert.exception(function() { sinon.assert.callOrder(s2, s1, s2); }); }); }); - describe("#1474 - promise library should be propagated through fakes and behaviors", function () { - + describe("#1474 - promise library should be propagated through fakes and behaviors", function() { var stub; function makeAssertions(fake, expected) { @@ -237,15 +248,17 @@ describe("issues", function () { assert.equals(fake.tap(), expected); } - before(function () { - if (!global.Promise) { this.skip(); } + before(function() { + if (!global.Promise) { + this.skip(); + } }); - beforeEach(function () { + beforeEach(function() { var promiseLib = { - resolve: function (value) { + resolve: function(value) { var promise = Promise.resolve(value); - promise.tap = function () { + promise.tap = function() { return "tap " + value; }; @@ -258,14 +271,14 @@ describe("issues", function () { stub.resolves("resolved"); }); - it("stub.onCall", function () { + it("stub.onCall", function() { stub.onSecondCall().resolves("resolved again"); makeAssertions(stub(), "tap resolved"); makeAssertions(stub(), "tap resolved again"); }); - it("stub.withArgs", function () { + it("stub.withArgs", function() { stub.withArgs(42).resolves("resolved again"); stub.withArgs(true).resolves("okay"); @@ -275,8 +288,7 @@ describe("issues", function () { }); }); - - describe("#1456", function () { + describe("#1456", function() { var sandbox; function throwsOnUnconfigurableProperty() { @@ -292,52 +304,58 @@ describe("issues", function () { /* eslint-enable no-restricted-syntax */ } - beforeEach(function () { - if (typeof window === "undefined" || throwsOnUnconfigurableProperty()) { this.skip(); } + beforeEach(function() { + if (typeof window === "undefined" || throwsOnUnconfigurableProperty()) { + this.skip(); + } sandbox = sinon.createSandbox(); }); - afterEach(function () { + afterEach(function() { sandbox.restore(); }); - it("stub window innerHeight", function () { + it("stub window innerHeight", function() { sandbox.stub(window, "innerHeight").value(111); assert.equals(window.innerHeight, 111); }); }); - describe("#1487 - withArgs() returnValue", function () { - beforeEach(function () { + describe("#1487 - withArgs() returnValue", function() { + beforeEach(function() { this.stub = createStub().throws("Nothing set"); this.stub.withArgs("arg").returns("return value"); this.stub("arg"); }); - it("sets correct firstCall.returnValue", function () { + it("sets correct firstCall.returnValue", function() { assert.equals(this.stub.withArgs("arg").firstCall.returnValue, "return value"); }); - it("sets correct lastCall.returnValue", function () { + it("sets correct lastCall.returnValue", function() { assert.equals(this.stub.withArgs("arg").lastCall.returnValue, "return value"); }); }); - describe("#1512 - sandbox.stub(obj,protoMethod)", function () { + describe("#1512 - sandbox.stub(obj,protoMethod)", function() { var sandbox; - beforeEach(function () { + beforeEach(function() { sandbox = sinon.createSandbox(); }); - afterEach(function () { + afterEach(function() { sandbox.restore(); }); - it("can stub methods on the prototype", function () { - var proto = { someFunction: function () { return; } }; + it("can stub methods on the prototype", function() { + var proto = { + someFunction: function() { + return; + } + }; var instance = Object.create(proto); var stub = sandbox.stub(instance, "someFunction"); @@ -346,44 +364,47 @@ describe("issues", function () { }); }); - describe("#1521 - stubbing Array.prototype.filter", function () { + describe("#1521 - stubbing Array.prototype.filter", function() { var orgFilter; - before(function () { + before(function() { orgFilter = Array.prototype.filter; }); - afterEach(function () { + afterEach(function() { /* eslint-disable no-extend-native */ Array.prototype.filter = orgFilter; }); - it("should be possible stub filter", function () { + it("should be possible stub filter", function() { var stub = sinon.stub(Array.prototype, "filter"); - [1, 2, 3].filter(function () { return false; }); + [1, 2, 3].filter(function() { + return false; + }); assert(stub.calledOnce); }); - }); - describe("#1531 - some copied functions on root sinon module throw", function () { - it("should create a fake server without throwing", function () { - refute.exception(function () { + describe("#1531 - some copied functions on root sinon module throw", function() { + it("should create a fake server without throwing", function() { + refute.exception(function() { sinon.createFakeServer(); }); }); - it("should create a fake server with clock without throwing", function () { - refute.exception(function () { + it("should create a fake server with clock without throwing", function() { + refute.exception(function() { sinon.createFakeServerWithClock(); }); }); }); - describe("#1442 - callThrough with a mock expectation", function () { - it("should call original method", function () { + describe("#1442 - callThrough with a mock expectation", function() { + it("should call original method", function() { var foo = { - bar: function () { return; } + bar: function() { + return; + } }; var mock = this.sandbox.mock(foo); @@ -395,10 +416,12 @@ describe("issues", function () { }); }); - describe("#1648 - resetHistory ", function () { - it("should reset property spies", function () { + describe("#1648 - resetHistory ", function() { + it("should reset property spies", function() { var obj = { - func: function () { return; }, + func: function() { + return; + }, get prop() { return 1; } @@ -427,8 +450,8 @@ describe("issues", function () { // this error was caused by overwriting methods with imported ones don't use the collection // and thus were not restorable - describe("#1775 - sinon.restore", function () { - it("should restore all stubs", function () { + describe("#1775 - sinon.restore", function() { + it("should restore all stubs", function() { var myApi = { someMethod: function someMethod() { // eslint-disable-next-line no-console @@ -442,7 +465,7 @@ describe("issues", function () { // TypeError: Attempted to wrap someMethod which is already wrapped }); - it("should restore all spies", function () { + it("should restore all spies", function() { var myApi = { someMethod: function someMethod() { // eslint-disable-next-line no-console @@ -456,7 +479,7 @@ describe("issues", function () { // TypeError: Attempted to wrap someMethod which is already wrapped }); - it("should restore all mocks", function () { + it("should restore all mocks", function() { var myApi = { someMethod: function someMethod() { // eslint-disable-next-line no-console @@ -471,8 +494,8 @@ describe("issues", function () { }); }); - describe("#1801 - sinon.restore spied fakeTimers", function () { - it("should restore spied fake timers", function () { + describe("#1801 - sinon.restore spied fakeTimers", function() { + it("should restore spied fake timers", function() { var originalSetTimeout = setTimeout; sinon.useFakeTimers(); @@ -484,19 +507,18 @@ describe("issues", function () { }); }); - describe("#1840 - sinon.restore useFakeXMLHttpRequest", function () { - it("should restore XMLHttpRequest and ActiveXObject", function () { + describe("#1840 - sinon.restore useFakeXMLHttpRequest", function() { + it("should restore XMLHttpRequest and ActiveXObject", function() { sinon.useFakeXMLHttpRequest(); sinon.restore(); assert.same(global.XMLHttpRequest, globalXHR); assert.same(global.ActiveXObject, globalAXO); }); - }); - describe("#1709 - deepEqual fails on cyclic references", function () { - it("should not blow up", function () { + describe("#1709 - deepEqual fails on cyclic references", function() { + it("should not blow up", function() { var spy = sinon.spy(); var firstObj = {}; @@ -511,11 +533,11 @@ describe("issues", function () { }); }); - describe("#1796 - cannot stub Array.prototype.sort", function () { - it("it should not fail with RangeError", function () { + describe("#1796 - cannot stub Array.prototype.sort", function() { + it("it should not fail with RangeError", function() { var stub = sinon.stub(Array.prototype, "sort"); - refute.exception(function () { + refute.exception(function() { [1, 2, 3].sort(); }); @@ -523,8 +545,8 @@ describe("issues", function () { }); }); - describe("#1900 - calledWith returns false positive", function () { - it("should return false when call args don't match", function () { + describe("#1900 - calledWith returns false positive", function() { + it("should return false when call args don't match", function() { var spy = sinon.spy(); var dateOne = new Date("2018-07-01"); var dateTwo = new Date("2018-07-31"); @@ -536,10 +558,14 @@ describe("issues", function () { }); }); - describe("#1882", function () { - it("should use constructor name when checking deepEquality", function () { - function ClassWithoutProps() { return; } - function AnotherClassWithoutProps() { return; } + describe("#1882", function() { + it("should use constructor name when checking deepEquality", function() { + function ClassWithoutProps() { + return; + } + function AnotherClassWithoutProps() { + return; + } ClassWithoutProps.prototype.constructor = ClassWithoutProps; AnotherClassWithoutProps.prototype.constructor = AnotherClassWithoutProps; var arg1 = new ClassWithoutProps(); //arg1.constructor.name === ClassWithoutProps @@ -551,8 +577,8 @@ describe("issues", function () { }); }); - describe("#1887", function () { - it("should not break stub behavior using multiple `match.any`", function () { + describe("#1887", function() { + it("should not break stub behavior using multiple `match.any`", function() { var stub = sinon.stub(); stub.withArgs(sinon.match.any, sinon.match.any, sinon.match("a")).returns("a"); diff --git a/test/match-test.js b/test/match-test.js index 295b613a2..2158fb69f 100644 --- a/test/match-test.js +++ b/test/match-test.js @@ -6,70 +6,82 @@ var refute = referee.refute; var sinonMatch = require("../lib/sinon/match"); function propertyMatcherTests(matcher, additionalTests) { - return function () { - it("returns matcher", function () { + return function() { + it("returns matcher", function() { var has = matcher("foo"); assert(sinonMatch.isMatcher(has)); }); - it("throws if first argument is not string", function () { - assert.exception(function () { - matcher(); - }, {name: "TypeError"}); - assert.exception(function () { - matcher(123); - }, {name: "TypeError"}); + it("throws if first argument is not string", function() { + assert.exception( + function() { + matcher(); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + matcher(123); + }, + { name: "TypeError" } + ); }); - it("returns false if value is undefined or null", function () { + it("returns false if value is undefined or null", function() { var has = matcher("foo"); assert.isFalse(has.test(undefined)); assert.isFalse(has.test(null)); }); - it("returns true if object has property", function () { + it("returns true if object has property", function() { var has = matcher("foo"); assert(has.test({ foo: null })); }); - it("returns false if object value is not equal to given value", function () { + it("returns false if object value is not equal to given value", function() { var has = matcher("foo", 1); assert.isFalse(has.test({ foo: null })); }); - it("returns true if object value is equal to given value", function () { + it("returns true if object value is equal to given value", function() { var has = matcher("message", "sinon rocks"); assert(has.test({ message: "sinon rocks" })); assert(has.test(new Error("sinon rocks"))); }); - it("returns true if string property matches", function () { + it("returns true if string property matches", function() { var has = matcher("length", 5); assert(has.test("sinon")); }); - it("allows to expect undefined", function () { + it("allows to expect undefined", function() { var has = matcher("foo", undefined); assert.isFalse(has.test({ foo: 1 })); }); - it("compares value deeply", function () { + it("compares value deeply", function() { var has = matcher("foo", { bar: "doo", test: 42 }); assert(has.test({ foo: { bar: "doo", test: 42 } })); }); - it("compares with matcher", function () { + it("compares with matcher", function() { var has = matcher("callback", sinonMatch.typeOf("function")); - assert(has.test({ callback: function () { return; } })); + assert( + has.test({ + callback: function() { + return; + } + }) + ); }); if (typeof additionalTests === "function") { @@ -78,64 +90,68 @@ function propertyMatcherTests(matcher, additionalTests) { }; } -describe("sinonMatch", function () { - it("returns matcher", function () { - var match = sinonMatch(function () { return; }); +describe("sinonMatch", function() { + it("returns matcher", function() { + var match = sinonMatch(function() { + return; + }); assert(sinonMatch.isMatcher(match)); }); - it("exposes test function", function () { - var test = function () { return; }; + it("exposes test function", function() { + var test = function() { + return; + }; var match = sinonMatch(test); assert.same(match.test, test); }); - it("returns true if properties are equal", function () { + it("returns true if properties are equal", function() { var match = sinonMatch({ str: "sinon", nr: 1 }); assert(match.test({ str: "sinon", nr: 1, other: "ignored" })); }); - it("returns true if properties are deep equal", function () { + it("returns true if properties are deep equal", function() { var match = sinonMatch({ deep: { str: "sinon" } }); assert(match.test({ deep: { str: "sinon", ignored: "value" } })); }); - it("returns false if a property is not equal", function () { + it("returns false if a property is not equal", function() { var match = sinonMatch({ str: "sinon", nr: 1 }); assert.isFalse(match.test({ str: "sinon", nr: 2 })); }); - it("returns false if a property is missing", function () { + it("returns false if a property is missing", function() { var match = sinonMatch({ str: "sinon", nr: 1 }); assert.isFalse(match.test({ nr: 1 })); }); - it("returns true if array is equal", function () { + it("returns true if array is equal", function() { var match = sinonMatch({ arr: ["a", "b"] }); assert(match.test({ arr: ["a", "b"] })); }); - it("returns false if array is not equal", function () { + it("returns false if array is not equal", function() { var match = sinonMatch({ arr: ["b", "a"] }); assert.isFalse(match.test({ arr: ["a", "b"] })); }); - it("returns false if array is not equal (even if the contents would match (deep equal))", function () { + it("returns false if array is not equal (even if the contents would match (deep equal))", function() { var match = sinonMatch([{ str: "sinon" }]); assert.isFalse(match.test([{ str: "sinon", ignored: "value" }])); }); - it("returns true if number objects are equal", function () { + it("returns true if number objects are equal", function() { /*eslint-disable no-new-wrappers*/ var match = sinonMatch({ one: new Number(1) }); @@ -143,68 +159,68 @@ describe("sinonMatch", function () { /*eslint-enable no-new-wrappers*/ }); - it("returns true if test matches", function () { + it("returns true if test matches", function() { var match = sinonMatch({ prop: sinonMatch.typeOf("boolean") }); assert(match.test({ prop: true })); }); - it("returns false if test does not match", function () { + it("returns false if test does not match", function() { var match = sinonMatch({ prop: sinonMatch.typeOf("boolean") }); assert.isFalse(match.test({ prop: "no" })); }); - it("returns true if deep test matches", function () { + it("returns true if deep test matches", function() { var match = sinonMatch({ deep: { prop: sinonMatch.typeOf("boolean") } }); assert(match.test({ deep: { prop: true } })); }); - it("returns false if deep test does not match", function () { + it("returns false if deep test does not match", function() { var match = sinonMatch({ deep: { prop: sinonMatch.typeOf("boolean") } }); assert.isFalse(match.test({ deep: { prop: "no" } })); }); - it("returns false if tested value is null or undefined", function () { + it("returns false if tested value is null or undefined", function() { var match = sinonMatch({}); assert.isFalse(match.test(null)); assert.isFalse(match.test(undefined)); }); - it("returns true if error message matches", function () { + it("returns true if error message matches", function() { var match = sinonMatch({ message: "evil error" }); assert(match.test(new Error("evil error"))); }); - it("returns true if string property matches", function () { + it("returns true if string property matches", function() { var match = sinonMatch({ length: 5 }); assert(match.test("sinon")); }); - it("returns true if number property matches", function () { + it("returns true if number property matches", function() { var match = sinonMatch({ toFixed: sinonMatch.func }); assert(match.test(0)); }); - it("returns true for string match", function () { + it("returns true for string match", function() { var match = sinonMatch("sinon"); assert(match.test("sinon")); }); - it("returns true for substring match", function () { + it("returns true for substring match", function() { var match = sinonMatch("no"); assert(match.test("sinon")); }); - it("returns false for string mismatch", function () { + it("returns false for string mismatch", function() { var match = sinonMatch("Sinon.JS"); assert.isFalse(match.test(null)); @@ -213,19 +229,19 @@ describe("sinonMatch", function () { assert.isFalse(match.test("sinon.js")); }); - it("returns true for regexp match", function () { + it("returns true for regexp match", function() { var match = sinonMatch(/^[sino]+$/); assert(match.test("sinon")); }); - it("returns false for regexp string mismatch", function () { + it("returns false for regexp string mismatch", function() { var match = sinonMatch(/^[sin]+$/); assert.isFalse(match.test("sinon")); }); - it("returns false for regexp type mismatch", function () { + it("returns false for regexp type mismatch", function() { var match = sinonMatch(/.*/); assert.isFalse(match.test()); @@ -234,7 +250,7 @@ describe("sinonMatch", function () { assert.isFalse(match.test({})); }); - it("returns true for number match", function () { + it("returns true for number match", function() { var match = sinonMatch(1); assert(match.test(1)); @@ -242,7 +258,7 @@ describe("sinonMatch", function () { assert(match.test(true)); }); - it("returns false for number mismatch", function () { + it("returns false for number mismatch", function() { var match = sinonMatch(1); assert.isFalse(match.test()); @@ -252,7 +268,7 @@ describe("sinonMatch", function () { assert.isFalse(match.test({})); }); - it("returns true for Symbol match", function () { + it("returns true for Symbol match", function() { if (typeof Symbol === "function") { var symbol = Symbol(); @@ -262,7 +278,7 @@ describe("sinonMatch", function () { } }); - it("returns false for Symbol mismatch", function () { + it("returns false for Symbol mismatch", function() { if (typeof Symbol === "function") { var match = sinonMatch(Symbol()); @@ -273,7 +289,7 @@ describe("sinonMatch", function () { } }); - it("returns true for Symbol inside object", function () { + it("returns true for Symbol inside object", function() { if (typeof Symbol === "function") { var symbol = Symbol(); @@ -283,82 +299,96 @@ describe("sinonMatch", function () { } }); - it("returns true if test function in object returns true", function () { - var match = sinonMatch({ test: function () { - return true; - }}); + it("returns true if test function in object returns true", function() { + var match = sinonMatch({ + test: function() { + return true; + } + }); assert(match.test()); }); - it("returns false if test function in object returns false", function () { - var match = sinonMatch({ test: function () { - return false; - }}); + it("returns false if test function in object returns false", function() { + var match = sinonMatch({ + test: function() { + return false; + } + }); assert.isFalse(match.test()); }); - it("returns false if test function in object returns nothing", function () { - var match = sinonMatch({ test: function () { return; }}); + it("returns false if test function in object returns nothing", function() { + var match = sinonMatch({ + test: function() { + return; + } + }); assert.isFalse(match.test()); }); - it("passes actual value to test function in object", function () { - var match = sinonMatch({ test: function (arg) { - return arg; - }}); + it("passes actual value to test function in object", function() { + var match = sinonMatch({ + test: function(arg) { + return arg; + } + }); assert(match.test(true)); }); - it("uses matcher", function () { + it("uses matcher", function() { var match = sinonMatch(sinonMatch("test")); assert(match.test("testing")); }); - describe(".toString", function () { - it("returns message", function () { + describe(".toString", function() { + it("returns message", function() { var message = "hello sinonMatch"; - var match = sinonMatch(function () { return; }, message); + var match = sinonMatch(function() { + return; + }, message); assert.same(match.toString(), message); }); - it("defaults to match(functionName)", function () { - var match = sinonMatch(function custom() { return; }); + it("defaults to match(functionName)", function() { + var match = sinonMatch(function custom() { + return; + }); assert.same(match.toString(), "match(custom)"); }); }); - describe(".any", function () { - it("is matcher", function () { + describe(".any", function() { + it("is matcher", function() { assert(sinonMatch.isMatcher(sinonMatch.any)); }); - it("returns true when tested", function () { + it("returns true when tested", function() { assert(sinonMatch.any.test()); }); }); - describe(".defined", function () { - it("is matcher", function () { + describe(".defined", function() { + it("is matcher", function() { assert(sinonMatch.isMatcher(sinonMatch.defined)); }); - it("returns false if test is called with null", function () { + it("returns false if test is called with null", function() { assert.isFalse(sinonMatch.defined.test(null)); }); - it("returns false if test is called with undefined", function () { + it("returns false if test is called with undefined", function() { assert.isFalse(sinonMatch.defined.test(undefined)); }); - it("returns true if test is called with any value", function () { + it("returns true if test is called with any value", function() { assert(sinonMatch.defined.test(false)); assert(sinonMatch.defined.test(true)); assert(sinonMatch.defined.test(0)); @@ -366,24 +396,28 @@ describe("sinonMatch", function () { assert(sinonMatch.defined.test("")); }); - it("returns true if test is called with any object", function () { + it("returns true if test is called with any object", function() { assert(sinonMatch.defined.test({})); - assert(sinonMatch.defined.test(function () { return; })); + assert( + sinonMatch.defined.test(function() { + return; + }) + ); }); }); - describe(".truthy", function () { - it("is matcher", function () { + describe(".truthy", function() { + it("is matcher", function() { assert(sinonMatch.isMatcher(sinonMatch.truthy)); }); - it("returns true if test is called with trueish value", function () { + it("returns true if test is called with trueish value", function() { assert(sinonMatch.truthy.test(true)); assert(sinonMatch.truthy.test(1)); assert(sinonMatch.truthy.test("yes")); }); - it("returns false if test is called falsy value", function () { + it("returns false if test is called falsy value", function() { assert.isFalse(sinonMatch.truthy.test(false)); assert.isFalse(sinonMatch.truthy.test(null)); assert.isFalse(sinonMatch.truthy.test(undefined)); @@ -391,40 +425,40 @@ describe("sinonMatch", function () { }); }); - describe(".falsy", function () { - it("is matcher", function () { + describe(".falsy", function() { + it("is matcher", function() { assert(sinonMatch.isMatcher(sinonMatch.falsy)); }); - it("returns true if test is called falsy value", function () { + it("returns true if test is called falsy value", function() { assert(sinonMatch.falsy.test(false)); assert(sinonMatch.falsy.test(null)); assert(sinonMatch.falsy.test(undefined)); assert(sinonMatch.falsy.test("")); }); - it("returns false if test is called with trueish value", function () { + it("returns false if test is called with trueish value", function() { assert.isFalse(sinonMatch.falsy.test(true)); assert.isFalse(sinonMatch.falsy.test(1)); assert.isFalse(sinonMatch.falsy.test("yes")); }); }); - describe(".same", function () { - it("returns matcher", function () { + describe(".same", function() { + it("returns matcher", function() { var same = sinonMatch.same(); assert(sinonMatch.isMatcher(same)); }); - it("returns true if test is called with same argument", function () { + it("returns true if test is called with same argument", function() { var object = {}; var same = sinonMatch.same(object); assert(same.test(object)); }); - it("returns true if test is called with same symbol", function () { + it("returns true if test is called with same symbol", function() { if (typeof Symbol === "function") { var symbol = Symbol(); var same = sinonMatch.same(symbol); @@ -433,82 +467,97 @@ describe("sinonMatch", function () { } }); - it("returns false if test is not called with same argument", function () { + it("returns false if test is not called with same argument", function() { var same = sinonMatch.same({}); assert.isFalse(same.test({})); }); }); - describe(".in", function () { - it("returns matcher", function () { + describe(".in", function() { + it("returns matcher", function() { var inMatcher = sinonMatch.in([]); assert(sinonMatch.isMatcher(inMatcher)); }); - it("throws if given argument is not an array", function () { + it("throws if given argument is not an array", function() { var arg = "not-array"; - assert.exception(function () { - sinonMatch.in(arg); - }, {name: "TypeError", message: "array expected"}); + assert.exception( + function() { + sinonMatch.in(arg); + }, + { name: "TypeError", message: "array expected" } + ); }); - describe("when given argument is an array", function () { + describe("when given argument is an array", function() { var arrays = [ [1, 2, 3], ["a", "b", "c"], - [{ a: "a" }, { b: "b"}], - [function () { return; }, function () { return; }], + [{ a: "a" }, { b: "b" }], + [ + function() { + return; + }, + function() { + return; + } + ], [null, undefined] ]; - it("returns true if the tested value in the given array", function () { - arrays.forEach(function (array) { + it("returns true if the tested value in the given array", function() { + arrays.forEach(function(array) { var inMatcher = sinonMatch.in(array); assert.isTrue(inMatcher.test(array[0])); }); }); - it("returns false if the tested value not in the given array", function () { - arrays.forEach(function (array) { + it("returns false if the tested value not in the given array", function() { + arrays.forEach(function(array) { var inMatcher = sinonMatch.in(array); assert.isFalse(inMatcher.test("something else")); }); }); - }); }); - describe(".typeOf", function () { - it("throws if given argument is not a string", function () { - assert.exception(function () { - sinonMatch.typeOf(); - }, {name: "TypeError"}); - assert.exception(function () { - sinonMatch.typeOf(123); - }, {name: "TypeError"}); - }); - - it("returns matcher", function () { + describe(".typeOf", function() { + it("throws if given argument is not a string", function() { + assert.exception( + function() { + sinonMatch.typeOf(); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + sinonMatch.typeOf(123); + }, + { name: "TypeError" } + ); + }); + + it("returns matcher", function() { var typeOf = sinonMatch.typeOf("string"); assert(sinonMatch.isMatcher(typeOf)); }); - it("returns true if test is called with string", function () { + it("returns true if test is called with string", function() { var typeOf = sinonMatch.typeOf("string"); assert(typeOf.test("Sinon.JS")); }); - it("returns false if test is not called with string", function () { + it("returns false if test is not called with string", function() { var typeOf = sinonMatch.typeOf("string"); assert.isFalse(typeOf.test(123)); }); - it("returns true if test is called with symbol", function () { + it("returns true if test is called with symbol", function() { if (typeof Symbol === "function") { var typeOf = sinonMatch.typeOf("symbol"); @@ -516,50 +565,60 @@ describe("sinonMatch", function () { } }); - it("returns true if test is called with regexp", function () { + it("returns true if test is called with regexp", function() { var typeOf = sinonMatch.typeOf("regexp"); assert(typeOf.test(/.+/)); }); - it("returns false if test is not called with regexp", function () { + it("returns false if test is not called with regexp", function() { var typeOf = sinonMatch.typeOf("regexp"); assert.isFalse(typeOf.test(true)); }); }); - describe(".instanceOf", function () { - it("throws if given argument is not a function", function () { - assert.exception(function () { - sinonMatch.instanceOf(); - }, {name: "TypeError"}); - assert.exception(function () { - sinonMatch.instanceOf("foo"); - }, {name: "TypeError"}); + describe(".instanceOf", function() { + it("throws if given argument is not a function", function() { + assert.exception( + function() { + sinonMatch.instanceOf(); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + sinonMatch.instanceOf("foo"); + }, + { name: "TypeError" } + ); }); if (typeof Symbol !== "undefined" && typeof Symbol.hasInstance !== "undefined") { - it("does not throw if given argument defines Symbol.hasInstance", function () { + it("does not throw if given argument defines Symbol.hasInstance", function() { var objectWithCustomTypeChecks = {}; - objectWithCustomTypeChecks[Symbol.hasInstance] = function () { return; }; + objectWithCustomTypeChecks[Symbol.hasInstance] = function() { + return; + }; sinonMatch.instanceOf(objectWithCustomTypeChecks); }); } - it("returns matcher", function () { - var instanceOf = sinonMatch.instanceOf(function () { return; }); + it("returns matcher", function() { + var instanceOf = sinonMatch.instanceOf(function() { + return; + }); assert(sinonMatch.isMatcher(instanceOf)); }); - it("returns true if test is called with instance of argument", function () { + it("returns true if test is called with instance of argument", function() { var instanceOf = sinonMatch.instanceOf(Array); assert(instanceOf.test([])); }); - it("returns false if test is not called with instance of argument", function () { + it("returns false if test is not called with instance of argument", function() { var instanceOf = sinonMatch.instanceOf(Array); assert.isFalse(instanceOf.test({})); @@ -569,54 +628,55 @@ describe("sinonMatch", function () { describe(".has", propertyMatcherTests(sinonMatch.has)); describe(".hasOwn", propertyMatcherTests(sinonMatch.hasOwn)); - describe(".hasNested", propertyMatcherTests(sinonMatch.hasNested, function () { - - it("compares nested value", function () { - var hasNested = sinonMatch.hasNested("foo.bar", "doo"); - - assert(hasNested.test({ foo: { bar: "doo" } })); - }); + describe( + ".hasNested", + propertyMatcherTests(sinonMatch.hasNested, function() { + it("compares nested value", function() { + var hasNested = sinonMatch.hasNested("foo.bar", "doo"); - it("compares nested array value", function () { - var hasNested = sinonMatch.hasNested("foo[0].bar", "doo"); + assert(hasNested.test({ foo: { bar: "doo" } })); + }); - assert(hasNested.test({ foo: [{ bar: "doo" }] })); - }); + it("compares nested array value", function() { + var hasNested = sinonMatch.hasNested("foo[0].bar", "doo"); - })); + assert(hasNested.test({ foo: [{ bar: "doo" }] })); + }); + }) + ); - describe(".hasSpecial", function () { - it("returns true if object has inherited property", function () { + describe(".hasSpecial", function() { + it("returns true if object has inherited property", function() { var has = sinonMatch.has("toString"); assert(has.test({})); }); - it("only includes property in message", function () { + it("only includes property in message", function() { var has = sinonMatch.has("test"); - assert.equals(has.toString(), "has(\"test\")"); + assert.equals(has.toString(), 'has("test")'); }); - it("includes property and value in message", function () { + it("includes property and value in message", function() { var has = sinonMatch.has("test", undefined); - assert.equals(has.toString(), "has(\"test\", undefined)"); + assert.equals(has.toString(), 'has("test", undefined)'); }); - it("returns true if string function matches", function () { + it("returns true if string function matches", function() { var has = sinonMatch.has("toUpperCase", sinonMatch.func); assert(has.test("sinon")); }); - it("returns true if number function matches", function () { + it("returns true if number function matches", function() { var has = sinonMatch.has("toFixed", sinonMatch.func); assert(has.test(0)); }); - it("returns true if object has Symbol", function () { + it("returns true if object has Symbol", function() { if (typeof Symbol === "function") { var symbol = Symbol(); @@ -626,7 +686,7 @@ describe("sinonMatch", function () { } }); - it("returns true if embedded object has Symbol", function () { + it("returns true if embedded object has Symbol", function() { if (typeof Symbol === "function") { var symbol = Symbol(); @@ -637,86 +697,99 @@ describe("sinonMatch", function () { }); }); - describe(".hasOwnSpecial", function () { - it("returns false if object has inherited property", function () { + describe(".hasOwnSpecial", function() { + it("returns false if object has inherited property", function() { var hasOwn = sinonMatch.hasOwn("toString"); assert.isFalse(hasOwn.test({})); }); - it("only includes property in message", function () { + it("only includes property in message", function() { var hasOwn = sinonMatch.hasOwn("test"); - assert.equals(hasOwn.toString(), "hasOwn(\"test\")"); + assert.equals(hasOwn.toString(), 'hasOwn("test")'); }); - it("includes property and value in message", function () { + it("includes property and value in message", function() { var hasOwn = sinonMatch.hasOwn("test", undefined); - assert.equals(hasOwn.toString(), "hasOwn(\"test\", undefined)"); + assert.equals(hasOwn.toString(), 'hasOwn("test", undefined)'); }); }); - describe(".every", function () { - it("throws if given argument is not a matcher", function () { - assert.exception(function () { - sinonMatch.every({}); - }, {name: "TypeError"}); - assert.exception(function () { - sinonMatch.every(123); - }, {name: "TypeError"}); - assert.exception(function () { - sinonMatch.every("123"); - }, {name: "TypeError"}); - }); - - it("returns matcher", function () { + describe(".every", function() { + it("throws if given argument is not a matcher", function() { + assert.exception( + function() { + sinonMatch.every({}); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + sinonMatch.every(123); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + sinonMatch.every("123"); + }, + { name: "TypeError" } + ); + }); + + it("returns matcher", function() { var every = sinonMatch.every(sinonMatch.any); assert(sinonMatch.isMatcher(every)); }); - it("wraps the given matcher message with an \"every()\"", function () { + it('wraps the given matcher message with an "every()"', function() { var every = sinonMatch.every(sinonMatch.number); - assert.equals(every.toString(), "every(typeOf(\"number\"))"); + assert.equals(every.toString(), 'every(typeOf("number"))'); }); - it("fails to match anything that is not an object or an iterable", function () { + it("fails to match anything that is not an object or an iterable", function() { var every = sinonMatch.every(sinonMatch.any); refute(every.test(1)); refute(every.test("a")); refute(every.test(null)); - refute(every.test(function () { return; })); + refute( + every.test(function() { + return; + }) + ); }); - it("matches an object if the predicate is true for every property", function () { + it("matches an object if the predicate is true for every property", function() { var every = sinonMatch.every(sinonMatch.number); - assert(every.test({a: 1, b: 2})); + assert(every.test({ a: 1, b: 2 })); }); - it("fails if the predicate is false for some of the object properties", function () { + it("fails if the predicate is false for some of the object properties", function() { var every = sinonMatch.every(sinonMatch.number); - refute(every.test({a: 1, b: "b"})); + refute(every.test({ a: 1, b: "b" })); }); - it("matches an array if the predicate is true for every element", function () { + it("matches an array if the predicate is true for every element", function() { var every = sinonMatch.every(sinonMatch.number); assert(every.test([1, 2])); }); - it("fails if the predicate is false for some of the array elements", function () { + it("fails if the predicate is false for some of the array elements", function() { var every = sinonMatch.every(sinonMatch.number); refute(every.test([1, "b"])); }); if (typeof Set === "function") { - it("matches an iterable if the predicate is true for every element", function () { + it("matches an iterable if the predicate is true for every element", function() { var every = sinonMatch.every(sinonMatch.number); var set = new Set(); set.add(1); @@ -725,7 +798,7 @@ describe("sinonMatch", function () { assert(every.test(set)); }); - it("fails if the predicate is false for some of the iterable elements", function () { + it("fails if the predicate is false for some of the iterable elements", function() { var every = sinonMatch.every(sinonMatch.number); var set = new Set(); set.add(1); @@ -736,66 +809,79 @@ describe("sinonMatch", function () { } }); - describe(".some", function () { - it("throws if given argument is not a matcher", function () { - assert.exception(function () { - sinonMatch.some({}); - }, {name: "TypeError"}); - assert.exception(function () { - sinonMatch.some(123); - }, {name: "TypeError"}); - assert.exception(function () { - sinonMatch.some("123"); - }, {name: "TypeError"}); - }); - - it("returns matcher", function () { + describe(".some", function() { + it("throws if given argument is not a matcher", function() { + assert.exception( + function() { + sinonMatch.some({}); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + sinonMatch.some(123); + }, + { name: "TypeError" } + ); + assert.exception( + function() { + sinonMatch.some("123"); + }, + { name: "TypeError" } + ); + }); + + it("returns matcher", function() { var some = sinonMatch.some(sinonMatch.any); assert(sinonMatch.isMatcher(some)); }); - it("wraps the given matcher message with an \"some()\"", function () { + it('wraps the given matcher message with an "some()"', function() { var some = sinonMatch.some(sinonMatch.number); - assert.equals(some.toString(), "some(typeOf(\"number\"))"); + assert.equals(some.toString(), 'some(typeOf("number"))'); }); - it("fails to match anything that is not an object or an iterable", function () { + it("fails to match anything that is not an object or an iterable", function() { var some = sinonMatch.some(sinonMatch.any); refute(some.test(1)); refute(some.test("a")); refute(some.test(null)); - refute(some.test(function () { return; })); + refute( + some.test(function() { + return; + }) + ); }); - it("matches an object if the predicate is true for some of the properties", function () { + it("matches an object if the predicate is true for some of the properties", function() { var some = sinonMatch.some(sinonMatch.number); - assert(some.test({a: 1, b: "b"})); + assert(some.test({ a: 1, b: "b" })); }); - it("fails if the predicate is false for all of the object properties", function () { + it("fails if the predicate is false for all of the object properties", function() { var some = sinonMatch.some(sinonMatch.number); - refute(some.test({a: "a", b: "b"})); + refute(some.test({ a: "a", b: "b" })); }); - it("matches an array if the predicate is true for some element", function () { + it("matches an array if the predicate is true for some element", function() { var some = sinonMatch.some(sinonMatch.number); assert(some.test([1, "b"])); }); - it("fails if the predicate is false for all of the array elements", function () { + it("fails if the predicate is false for all of the array elements", function() { var some = sinonMatch.some(sinonMatch.number); refute(some.test(["a", "b"])); }); if (typeof Set === "function") { - it("matches an iterable if the predicate is true for some element", function () { + it("matches an iterable if the predicate is true for some element", function() { var some = sinonMatch.some(sinonMatch.number); var set = new Set(); set.add(1); @@ -804,169 +890,168 @@ describe("sinonMatch", function () { assert(some.test(set)); }); - it("fails if the predicate is false for all of the iterable elements", function () { + it("fails if the predicate is false for all of the iterable elements", function() { var some = sinonMatch.some(sinonMatch.number); var set = new Set(); set.add("a"); set.add("b"); - refute(some.test(set)); }); } }); - describe(".bool", function () { - it("is typeOf boolean matcher", function () { + describe(".bool", function() { + it("is typeOf boolean matcher", function() { var bool = sinonMatch.bool; assert(sinonMatch.isMatcher(bool)); - assert.equals(bool.toString(), "typeOf(\"boolean\")"); + assert.equals(bool.toString(), 'typeOf("boolean")'); }); }); - describe(".number", function () { - it("is typeOf number matcher", function () { + describe(".number", function() { + it("is typeOf number matcher", function() { var number = sinonMatch.number; assert(sinonMatch.isMatcher(number)); - assert.equals(number.toString(), "typeOf(\"number\")"); + assert.equals(number.toString(), 'typeOf("number")'); }); }); - describe(".string", function () { - it("is typeOf string matcher", function () { + describe(".string", function() { + it("is typeOf string matcher", function() { var string = sinonMatch.string; assert(sinonMatch.isMatcher(string)); - assert.equals(string.toString(), "typeOf(\"string\")"); + assert.equals(string.toString(), 'typeOf("string")'); }); }); - describe(".object", function () { - it("is typeOf object matcher", function () { + describe(".object", function() { + it("is typeOf object matcher", function() { var object = sinonMatch.object; assert(sinonMatch.isMatcher(object)); - assert.equals(object.toString(), "typeOf(\"object\")"); + assert.equals(object.toString(), 'typeOf("object")'); }); }); - describe(".func", function () { - it("is typeOf function matcher", function () { + describe(".func", function() { + it("is typeOf function matcher", function() { var func = sinonMatch.func; assert(sinonMatch.isMatcher(func)); - assert.equals(func.toString(), "typeOf(\"function\")"); + assert.equals(func.toString(), 'typeOf("function")'); }); }); - describe(".array", function () { - it("is typeOf array matcher", function () { + describe(".array", function() { + it("is typeOf array matcher", function() { var array = sinonMatch.array; assert(sinonMatch.isMatcher(array)); - assert.equals(array.toString(), "typeOf(\"array\")"); + assert.equals(array.toString(), 'typeOf("array")'); }); - describe("array.deepEquals", function () { - it("has a .deepEquals matcher", function () { + describe("array.deepEquals", function() { + it("has a .deepEquals matcher", function() { var deepEquals = sinonMatch.array.deepEquals([1, 2, 3]); assert(sinonMatch.isMatcher(deepEquals)); assert.equals(deepEquals.toString(), "deepEquals([1,2,3])"); }); - it("matches arrays with the exact same elements", function () { + it("matches arrays with the exact same elements", function() { var deepEquals = sinonMatch.array.deepEquals([1, 2, 3]); assert(deepEquals.test([1, 2, 3])); assert.isFalse(deepEquals.test([1, 2])); assert.isFalse(deepEquals.test([3])); }); - it("fails when passed a non-array object", function () { + it("fails when passed a non-array object", function() { var deepEquals = sinonMatch.array.deepEquals(["one", "two", "three"]); - assert.isFalse(deepEquals.test({0: "one", 1: "two", 2: "three", length: 3})); + assert.isFalse(deepEquals.test({ 0: "one", 1: "two", 2: "three", length: 3 })); }); }); - describe("array.startsWith", function () { - it("has a .startsWith matcher", function () { + describe("array.startsWith", function() { + it("has a .startsWith matcher", function() { var startsWith = sinonMatch.array.startsWith([1, 2]); assert(sinonMatch.isMatcher(startsWith)); assert.equals(startsWith.toString(), "startsWith([1,2])"); }); - it("matches arrays starting with the same elements", function () { + it("matches arrays starting with the same elements", function() { assert(sinonMatch.array.startsWith([1]).test([1, 2])); assert(sinonMatch.array.startsWith([1, 2]).test([1, 2])); assert.isFalse(sinonMatch.array.startsWith([1, 2, 3]).test([1, 2])); assert.isFalse(sinonMatch.array.startsWith([2]).test([1, 2])); }); - it("fails when passed a non-array object", function () { + it("fails when passed a non-array object", function() { var startsWith = sinonMatch.array.startsWith(["one", "two"]); - assert.isFalse(startsWith.test({0: "one", 1: "two", 2: "three", length: 3})); + assert.isFalse(startsWith.test({ 0: "one", 1: "two", 2: "three", length: 3 })); }); }); - describe("array.endsWith", function () { - it("has an .endsWith matcher", function () { + describe("array.endsWith", function() { + it("has an .endsWith matcher", function() { var endsWith = sinonMatch.array.endsWith([2, 3]); assert(sinonMatch.isMatcher(endsWith)); assert.equals(endsWith.toString(), "endsWith([2,3])"); }); - it("matches arrays ending with the same elements", function () { + it("matches arrays ending with the same elements", function() { assert(sinonMatch.array.endsWith([2]).test([1, 2])); assert(sinonMatch.array.endsWith([1, 2]).test([1, 2])); assert.isFalse(sinonMatch.array.endsWith([1, 2, 3]).test([1, 2])); assert.isFalse(sinonMatch.array.endsWith([3]).test([1, 2])); }); - it("fails when passed a non-array object", function () { + it("fails when passed a non-array object", function() { var endsWith = sinonMatch.array.endsWith(["two", "three"]); - assert.isFalse(endsWith.test({0: "one", 1: "two", 2: "three", length: 3})); + assert.isFalse(endsWith.test({ 0: "one", 1: "two", 2: "three", length: 3 })); }); }); - describe("array.contains", function () { - it("has a .contains matcher", function () { + describe("array.contains", function() { + it("has a .contains matcher", function() { var contains = sinonMatch.array.contains([2, 3]); assert(sinonMatch.isMatcher(contains)); assert.equals(contains.toString(), "contains([2,3])"); }); - it("matches arrays containing all the expected elements", function () { + it("matches arrays containing all the expected elements", function() { assert(sinonMatch.array.contains([2]).test([1, 2, 3])); assert(sinonMatch.array.contains([1, 2]).test([1, 2])); assert.isFalse(sinonMatch.array.contains([1, 2, 3]).test([1, 2])); assert.isFalse(sinonMatch.array.contains([3]).test([1, 2])); }); - it("fails when passed a non-array object", function () { + it("fails when passed a non-array object", function() { var contains = sinonMatch.array.contains(["one", "three"]); - assert.isFalse(contains.test({0: "one", 1: "two", 2: "three", length: 3})); + assert.isFalse(contains.test({ 0: "one", 1: "two", 2: "three", length: 3 })); }); }); }); - describe(".map", function () { - it("is typeOf map matcher", function () { + describe(".map", function() { + it("is typeOf map matcher", function() { var map = sinonMatch.map; assert(sinonMatch.isMatcher(map)); - assert.equals(map.toString(), "typeOf(\"map\")"); + assert.equals(map.toString(), 'typeOf("map")'); }); - describe("map.deepEquals", function () { + describe("map.deepEquals", function() { if (typeof Map === "function") { - it("has a .deepEquals matcher", function () { + it("has a .deepEquals matcher", function() { var mapOne = new Map(); mapOne.set("one", 1); mapOne.set("two", 2); @@ -977,7 +1062,7 @@ describe("sinonMatch", function () { assert.equals(deepEquals.toString(), "deepEquals(Map[['one',1],['two',2],['three',3]])"); }); - it("matches maps with the exact same elements", function () { + it("matches maps with the exact same elements", function() { var mapOne = new Map(); mapOne.set("one", 1); mapOne.set("two", 2); @@ -998,7 +1083,7 @@ describe("sinonMatch", function () { assert.isFalse(deepEquals.test(new Map())); }); - it("fails when maps have the same keys but different values", function () { + it("fails when maps have the same keys but different values", function() { var mapOne = new Map(); mapOne.set("one", 1); mapOne.set("two", 2); @@ -1019,7 +1104,7 @@ describe("sinonMatch", function () { assert.isFalse(deepEquals.test(mapThree)); }); - it("fails when passed a non-map object", function () { + it("fails when passed a non-map object", function() { var deepEquals = sinonMatch.array.deepEquals(new Map()); assert.isFalse(deepEquals.test({})); assert.isFalse(deepEquals.test([])); @@ -1027,9 +1112,9 @@ describe("sinonMatch", function () { } }); - describe("map.contains", function () { + describe("map.contains", function() { if (typeof Map === "function") { - it("has a .contains matcher", function () { + it("has a .contains matcher", function() { var mapOne = new Map(); mapOne.set("one", 1); mapOne.set("two", 2); @@ -1040,7 +1125,7 @@ describe("sinonMatch", function () { assert.equals(contains.toString(), "contains(Map[['one',1],['two',2],['three',3]])"); }); - it("matches maps containing the given elements", function () { + it("matches maps containing the given elements", function() { var mapOne = new Map(); mapOne.set("one", 1); mapOne.set("two", 2); @@ -1064,7 +1149,7 @@ describe("sinonMatch", function () { assert.isFalse(sinonMatch.map.contains(mapFour).test(mapOne)); }); - it("fails when maps contain the same keys but different values", function () { + it("fails when maps contain the same keys but different values", function() { var mapOne = new Map(); mapOne.set("one", 1); mapOne.set("two", 2); @@ -1084,7 +1169,7 @@ describe("sinonMatch", function () { assert.isFalse(sinonMatch.map.contains(mapThree).test(mapOne)); }); - it("fails when passed a non-map object", function () { + it("fails when passed a non-map object", function() { var contains = sinonMatch.map.contains(new Map()); assert.isFalse(contains.test({})); assert.isFalse(contains.test([])); @@ -1093,17 +1178,17 @@ describe("sinonMatch", function () { }); }); - describe(".set", function () { - it("is typeOf set matcher", function () { + describe(".set", function() { + it("is typeOf set matcher", function() { var set = sinonMatch.set; assert(sinonMatch.isMatcher(set)); - assert.equals(set.toString(), "typeOf(\"set\")"); + assert.equals(set.toString(), 'typeOf("set")'); }); - describe("set.deepEquals", function () { + describe("set.deepEquals", function() { if (typeof Set === "function") { - it("has a .deepEquals matcher", function () { + it("has a .deepEquals matcher", function() { var setOne = new Set(); setOne.add("one"); setOne.add("two"); @@ -1114,7 +1199,7 @@ describe("sinonMatch", function () { assert.equals(deepEquals.toString(), "deepEquals(Set['one','two','three'])"); }); - it("matches sets with the exact same elements", function () { + it("matches sets with the exact same elements", function() { var setOne = new Set(); setOne.add("one"); setOne.add("two"); @@ -1135,7 +1220,7 @@ describe("sinonMatch", function () { assert.isFalse(deepEquals.test(new Set())); }); - it("fails when passed a non-set object", function () { + it("fails when passed a non-set object", function() { var deepEquals = sinonMatch.array.deepEquals(new Set()); assert.isFalse(deepEquals.test({})); assert.isFalse(deepEquals.test([])); @@ -1143,9 +1228,9 @@ describe("sinonMatch", function () { } }); - describe("set.contains", function () { + describe("set.contains", function() { if (typeof Set === "function") { - it("has a .contains matcher", function () { + it("has a .contains matcher", function() { var setOne = new Set(); setOne.add("one"); setOne.add("two"); @@ -1156,7 +1241,7 @@ describe("sinonMatch", function () { assert.equals(contains.toString(), "contains(Set['one','two','three'])"); }); - it("matches sets containing the given elements", function () { + it("matches sets containing the given elements", function() { var setOne = new Set(); setOne.add("one"); setOne.add("two"); @@ -1180,7 +1265,7 @@ describe("sinonMatch", function () { assert.isFalse(sinonMatch.set.contains(setFour).test(setOne)); }); - it("fails when passed a non-set object", function () { + it("fails when passed a non-set object", function() { var contains = sinonMatch.set.contains(new Set()); assert.isFalse(contains.test({})); assert.isFalse(contains.test([])); @@ -1189,64 +1274,65 @@ describe("sinonMatch", function () { }); }); - describe(".regexp", function () { - it("is typeOf regexp matcher", function () { + describe(".regexp", function() { + it("is typeOf regexp matcher", function() { var regexp = sinonMatch.regexp; assert(sinonMatch.isMatcher(regexp)); - assert.equals(regexp.toString(), "typeOf(\"regexp\")"); + assert.equals(regexp.toString(), 'typeOf("regexp")'); }); }); - describe(".date", function () { - it("is typeOf regexp matcher", function () { + describe(".date", function() { + it("is typeOf regexp matcher", function() { var date = sinonMatch.date; assert(sinonMatch.isMatcher(date)); - assert.equals(date.toString(), "typeOf(\"date\")"); + assert.equals(date.toString(), 'typeOf("date")'); }); }); - describe(".symbol", function () { - it("is typeOf symbol matcher", function () { + describe(".symbol", function() { + it("is typeOf symbol matcher", function() { var symbol = sinonMatch.symbol; assert(sinonMatch.isMatcher(symbol)); - assert.equals(symbol.toString(), "typeOf(\"symbol\")"); + assert.equals(symbol.toString(), 'typeOf("symbol")'); }); }); - describe(".or", function () { - it("is matcher", function () { + describe(".or", function() { + it("is matcher", function() { var numberOrString = sinonMatch.number.or(sinonMatch.string); assert(sinonMatch.isMatcher(numberOrString)); - assert.equals(numberOrString.toString(), - "typeOf(\"number\").or(typeOf(\"string\"))"); + assert.equals(numberOrString.toString(), 'typeOf("number").or(typeOf("string"))'); }); - it("requires matcher argument", function () { - assert.exception(function () { - sinonMatch.instanceOf(Error).or(); - }, {name: "TypeError"}); + it("requires matcher argument", function() { + assert.exception( + function() { + sinonMatch.instanceOf(Error).or(); + }, + { name: "TypeError" } + ); }); - it("will coerce argument to matcher", function () { + it("will coerce argument to matcher", function() { var abcOrDef = sinonMatch("abc").or("def"); assert(sinonMatch.isMatcher(abcOrDef)); - assert.equals(abcOrDef.toString(), - "match(\"abc\").or(match(\"def\"))"); + assert.equals(abcOrDef.toString(), 'match("abc").or(match("def"))'); }); - it("returns true if either matcher matches", function () { + it("returns true if either matcher matches", function() { var numberOrString = sinonMatch.number.or(sinonMatch.string); assert(numberOrString.test(123)); assert(numberOrString.test("abc")); }); - it("returns false if neither matcher matches", function () { + it("returns false if neither matcher matches", function() { var numberOrAbc = sinonMatch.number.or("abc"); assert.isFalse(numberOrAbc.test(/.+/)); @@ -1254,7 +1340,7 @@ describe("sinonMatch", function () { assert.isFalse(numberOrAbc.test({})); }); - it("can be used with undefined", function () { + it("can be used with undefined", function() { var numberOrUndef = sinonMatch.number.or(undefined); assert(numberOrUndef.test(123)); @@ -1262,42 +1348,44 @@ describe("sinonMatch", function () { }); }); - describe(".and", function () { - it("is matcher", function () { + describe(".and", function() { + it("is matcher", function() { var fooAndBar = sinonMatch.has("foo").and(sinonMatch.has("bar")); assert(sinonMatch.isMatcher(fooAndBar)); - assert.equals(fooAndBar.toString(), "has(\"foo\").and(has(\"bar\"))"); + assert.equals(fooAndBar.toString(), 'has("foo").and(has("bar"))'); }); - it("requires matcher argument", function () { - assert.exception(function () { - sinonMatch.instanceOf(Error).and(); - }, {name: "TypeError"}); + it("requires matcher argument", function() { + assert.exception( + function() { + sinonMatch.instanceOf(Error).and(); + }, + { name: "TypeError" } + ); }); - it("will coerce to matcher", function () { - var abcOrObj = sinonMatch("abc").or({a: 1}); + it("will coerce to matcher", function() { + var abcOrObj = sinonMatch("abc").or({ a: 1 }); assert(sinonMatch.isMatcher(abcOrObj)); - assert.equals(abcOrObj.toString(), - "match(\"abc\").or(match(a: 1))"); + assert.equals(abcOrObj.toString(), 'match("abc").or(match(a: 1))'); }); - it("returns true if both matchers match", function () { + it("returns true if both matchers match", function() { var fooAndBar = sinonMatch.has("foo").and({ bar: "bar" }); assert(fooAndBar.test({ foo: "foo", bar: "bar" })); }); - it("returns false if either matcher does not match", function () { + it("returns false if either matcher does not match", function() { var fooAndBar = sinonMatch.has("foo").and(sinonMatch.has("bar")); assert.isFalse(fooAndBar.test({ foo: "foo" })); assert.isFalse(fooAndBar.test({ bar: "bar" })); }); - it("can be used with undefined", function () { + it("can be used with undefined", function() { var falsyAndUndefined = sinonMatch.falsy.and(undefined); assert.isFalse(falsyAndUndefined.test(false)); @@ -1305,14 +1393,14 @@ describe("sinonMatch", function () { }); }); - describe("nested", function () { - it("returns true for an object with nested matcher", function () { - var match = sinonMatch({outer: sinonMatch({ inner: "sinon" })}); + describe("nested", function() { + it("returns true for an object with nested matcher", function() { + var match = sinonMatch({ outer: sinonMatch({ inner: "sinon" }) }); - assert.isTrue(match.test({outer: { inner: "sinon", foo: "bar" }})); + assert.isTrue(match.test({ outer: { inner: "sinon", foo: "bar" } })); }); - it("returns true for an array of nested matchers", function () { + it("returns true for an array of nested matchers", function() { var match = sinonMatch([sinonMatch({ str: "sinon" })]); assert.isTrue(match.test([{ str: "sinon", foo: "bar" }])); diff --git a/test/mock-test.js b/test/mock-test.js index 8eeb55a3f..8360623d7 100644 --- a/test/mock-test.js +++ b/test/mock-test.js @@ -9,79 +9,89 @@ var sinonSpy = require("../lib/sinon/spy"); var assert = referee.assert; var refute = referee.refute; -describe("sinonMock", function () { - it("creates anonymous mock functions", function () { +describe("sinonMock", function() { + it("creates anonymous mock functions", function() { var expectation = sinonMock(); assert.equals(expectation.method, "Anonymous mock"); }); - it("creates named anonymous mock functions", function () { + it("creates named anonymous mock functions", function() { var expectation = sinonMock("functionName"); assert.equals(expectation.method, "functionName"); }); - describe(".create", function () { - it("returns function with expects method", function () { + describe(".create", function() { + it("returns function with expects method", function() { var mock = sinonMock.create({}); assert.isFunction(mock.expects); }); - it("throws without object", function () { - assert.exception(function () { - sinonMock.create(); - }, {name: "TypeError"}); + it("throws without object", function() { + assert.exception( + function() { + sinonMock.create(); + }, + { name: "TypeError" } + ); }); }); - describe(".expects", function () { - beforeEach(function () { - this.mock = sinonMock.create({ someMethod: function () { return; } }); + describe(".expects", function() { + beforeEach(function() { + this.mock = sinonMock.create({ + someMethod: function() { + return; + } + }); }); - it("throws without method", function () { + it("throws without method", function() { var mock = this.mock; - assert.exception(function () { - mock.expects(); - }, {name: "TypeError"}); + assert.exception( + function() { + mock.expects(); + }, + { name: "TypeError" } + ); }); - it("returns expectation", function () { + it("returns expectation", function() { var result = this.mock.expects("someMethod"); assert.isFunction(result); assert.equals(result.method, "someMethod"); }); - it("throws if expecting a non-existent method", function () { + it("throws if expecting a non-existent method", function() { var mock = this.mock; - assert.exception(function () { + assert.exception(function() { mock.expects("someMethod2"); }); }); }); - describe(".expectation", function () { - beforeEach(function () { + describe(".expectation", function() { + beforeEach(function() { this.method = "myMeth"; this.expectation = sinonExpectation.create(this.method); }); - it("creates unnamed expectation", function () { + it("creates unnamed expectation", function() { var anonMock = sinonExpectation.create(); anonMock.never(); assert(anonMock.verify()); }); - it("uses 'anonymous mock expectation' for unnamed expectation", function () { + it("uses 'anonymous mock expectation' for unnamed expectation", function() { var anonMock = sinonExpectation.create(); anonMock.once(); assert.exception( - function () { + function() { anonMock.verify(); }, { @@ -90,23 +100,23 @@ describe("sinonMock", function () { ); }); - it("call expectation", function () { + it("call expectation", function() { this.expectation(); assert.isFunction(this.expectation.invoke); assert(this.expectation.called); }); - it("is invokable", function () { + it("is invokable", function() { var expectation = this.expectation; - refute.exception(function () { + refute.exception(function() { expectation(); }); }); - describe(".returns", function () { - it("returns configured return value", function () { + describe(".returns", function() { + it("returns configured return value", function() { var object = {}; this.expectation.returns(object); @@ -114,8 +124,8 @@ describe("sinonMock", function () { }); }); - describe("call", function () { - it("is called with correct this value", function () { + describe("call", function() { + it("is called with correct this value", function() { var object = { method: this.expectation }; object.method(); @@ -123,17 +133,20 @@ describe("sinonMock", function () { }); }); - describe(".callCount", function () { - it("onlys be invokable once by default", function () { + describe(".callCount", function() { + it("onlys be invokable once by default", function() { var expectation = this.expectation; expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("throw readable error", function () { + it("throw readable error", function() { var expectation = this.expectation; expectation(); @@ -143,170 +156,203 @@ describe("sinonMock", function () { }); }); - describe(".callCountNever", function () { - it("is not callable", function () { + describe(".callCountNever", function() { + it("is not callable", function() { var expectation = this.expectation; expectation.never(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.never(), this.expectation); }); }); - describe(".callCountOnce", function () { - it("allows one call", function () { + describe(".callCountOnce", function() { + it("allows one call", function() { var expectation = this.expectation; expectation.once(); expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.once(), this.expectation); }); }); - describe(".callCountTwice", function () { - it("allows two calls", function () { + describe(".callCountTwice", function() { + it("allows two calls", function() { var expectation = this.expectation; expectation.twice(); expectation(); expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.twice(), this.expectation); }); }); - describe(".callCountThrice", function () { - it("allows three calls", function () { + describe(".callCountThrice", function() { + it("allows three calls", function() { var expectation = this.expectation; expectation.thrice(); expectation(); expectation(); expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.thrice(), this.expectation); }); }); - describe(".callCountExactly", function () { - it("allows specified number of calls", function () { + describe(".callCountExactly", function() { + it("allows specified number of calls", function() { var expectation = this.expectation; expectation.exactly(2); expectation(); expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.exactly(2), this.expectation); }); - it("throws without argument", function () { + it("throws without argument", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.exactly(); - }, {name: "TypeError"}); + assert.exception( + function() { + expectation.exactly(); + }, + { name: "TypeError" } + ); }); - it("throws without number", function () { + it("throws without number", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.exactly("12"); - }, {name: "TypeError"}); + assert.exception( + function() { + expectation.exactly("12"); + }, + { name: "TypeError" } + ); }); - it("throws with Symbol", function () { + it("throws with Symbol", function() { if (typeof Symbol === "function") { var expectation = this.expectation; - assert.exception(function () { - expectation.exactly(Symbol()); - }, function (err) { - return err.message === "'Symbol()' is not a number"; - }); + assert.exception( + function() { + expectation.exactly(Symbol()); + }, + function(err) { + return err.message === "'Symbol()' is not a number"; + } + ); } }); }); - describe(".atLeast", function () { - it("throws without argument", function () { + describe(".atLeast", function() { + it("throws without argument", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.atLeast(); - }, {name: "TypeError"}); + assert.exception( + function() { + expectation.atLeast(); + }, + { name: "TypeError" } + ); }); - it("throws without number", function () { + it("throws without number", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.atLeast({}); - }, {name: "TypeError"}); + assert.exception( + function() { + expectation.atLeast({}); + }, + { name: "TypeError" } + ); }); - it("throws with Symbol", function () { + it("throws with Symbol", function() { if (typeof Symbol === "function") { var expectation = this.expectation; - assert.exception(function () { - expectation.atLeast(Symbol()); - }, function (err) { - return err.message === "'Symbol()' is not number"; - }); + assert.exception( + function() { + expectation.atLeast(Symbol()); + }, + function(err) { + return err.message === "'Symbol()' is not number"; + } + ); } }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.atLeast(2), this.expectation); }); - it("allows any number of calls", function () { + it("allows any number of calls", function() { var expectation = this.expectation; expectation.atLeast(2); expectation(); expectation(); - refute.exception(function () { + refute.exception(function() { expectation(); expectation(); }); }); - it("should not be met with too few calls", function () { + it("should not be met with too few calls", function() { this.expectation.atLeast(2); this.expectation(); assert.isFalse(this.expectation.met()); }); - it("is met with exact calls", function () { + it("is met with exact calls", function() { this.expectation.atLeast(2); this.expectation(); this.expectation(); @@ -314,7 +360,7 @@ describe("sinonMock", function () { assert(this.expectation.met()); }); - it("is met with excessive calls", function () { + it("is met with excessive calls", function() { this.expectation.atLeast(2); this.expectation(); this.expectation(); @@ -323,25 +369,35 @@ describe("sinonMock", function () { assert(this.expectation.met()); }); - it("should not throw when exceeding at least expectation", function () { - var obj = { foobar: function () { return; } }; + it("should not throw when exceeding at least expectation", function() { + var obj = { + foobar: function() { + return; + } + }; var mock = sinonMock(obj); mock.expects("foobar").atLeast(1); obj.foobar(); - refute.exception(function () { + refute.exception(function() { obj.foobar(); mock.verify(); }); }); - it("should not throw when exceeding at least expectation and withargs", function () { - var obj = { foobar: function () { return; } }; + it("should not throw when exceeding at least expectation and withargs", function() { + var obj = { + foobar: function() { + return; + } + }; var mock = sinonMock(obj); mock.expects("foobar").withArgs("arg1"); - mock.expects("foobar").atLeast(1).withArgs("arg2"); + mock.expects("foobar") + .atLeast(1) + .withArgs("arg2"); obj.foobar("arg1"); obj.foobar("arg2"); @@ -351,56 +407,65 @@ describe("sinonMock", function () { }); }); - describe(".atMost", function () { - it("throws without argument", function () { + describe(".atMost", function() { + it("throws without argument", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.atMost(); - }, {name: "TypeError"}); + assert.exception( + function() { + expectation.atMost(); + }, + { name: "TypeError" } + ); }); - it("throws without number", function () { + it("throws without number", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.atMost({}); - }, {name: "TypeError"}); + assert.exception( + function() { + expectation.atMost({}); + }, + { name: "TypeError" } + ); }); - it("throws with Symbol", function () { + it("throws with Symbol", function() { if (typeof Symbol === "function") { var expectation = this.expectation; - assert.exception(function () { - expectation.atMost(Symbol()); - }, function (err) { - return err.message === "'Symbol()' is not number"; - }); + assert.exception( + function() { + expectation.atMost(Symbol()); + }, + function(err) { + return err.message === "'Symbol()' is not number"; + } + ); } }); - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.atMost(2), this.expectation); }); - it("allows fewer calls", function () { + it("allows fewer calls", function() { var expectation = this.expectation; expectation.atMost(2); - refute.exception(function () { + refute.exception(function() { expectation(); }); }); - it("is met with fewer calls", function () { + it("is met with fewer calls", function() { this.expectation.atMost(2); this.expectation(); assert(this.expectation.met()); }); - it("is met with exact calls", function () { + it("is met with exact calls", function() { this.expectation.atMost(2); this.expectation(); this.expectation(); @@ -408,40 +473,43 @@ describe("sinonMock", function () { assert(this.expectation.met()); }); - it("should not be met with excessive calls", function () { + it("should not be met with excessive calls", function() { var expectation = this.expectation; this.expectation.atMost(2); this.expectation(); this.expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); assert.isFalse(this.expectation.met()); }); }); - describe(".atMostAndAtLeast", function () { - beforeEach(function () { + describe(".atMostAndAtLeast", function() { + beforeEach(function() { this.expectation.atLeast(2); this.expectation.atMost(3); }); - it("should not be met with too few calls", function () { + it("should not be met with too few calls", function() { this.expectation(); assert.isFalse(this.expectation.met()); }); - it("is met with minimum calls", function () { + it("is met with minimum calls", function() { this.expectation(); this.expectation(); assert(this.expectation.met()); }); - it("is met with maximum calls", function () { + it("is met with maximum calls", function() { this.expectation(); this.expectation(); this.expectation(); @@ -449,30 +517,33 @@ describe("sinonMock", function () { assert(this.expectation.met()); }); - it("throws with excessive calls", function () { + it("throws with excessive calls", function() { var expectation = this.expectation; expectation(); expectation(); expectation(); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); }); - describe(".met", function () { - it("should not be met when not called enough times", function () { + describe(".met", function() { + it("should not be met when not called enough times", function() { assert.isFalse(this.expectation.met()); }); - it("is met when called enough times", function () { + it("is met when called enough times", function() { this.expectation(); assert(this.expectation.met()); }); - it("should not be met when called too many times", function () { + it("should not be met when called too many times", function() { this.expectation(); assert.exception(this.expectation); @@ -481,200 +552,232 @@ describe("sinonMock", function () { }); }); - describe(".withArgs", function () { - var expectedException = function (name) { + describe(".withArgs", function() { + var expectedException = function(name) { return { - test: function (actual) { + test: function(actual) { return actual.name === name; }, - toString: function () { + toString: function() { return name; } }; }; - it("returns expectation for chaining", function () { + it("returns expectation for chaining", function() { assert.same(this.expectation.withArgs(1), this.expectation); }); - it("accepts call with expected args", function () { + it("accepts call with expected args", function() { this.expectation.withArgs(1, 2, 3); this.expectation(1, 2, 3); assert(this.expectation.met()); }); - it("throws when called without args", function () { + it("throws when called without args", function() { var expectation = this.expectation; expectation.withArgs(1, 2, 3); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("throws when called with too few args", function () { + it("throws when called with too few args", function() { var expectation = this.expectation; expectation.withArgs(1, 2, 3); - assert.exception(function () { - expectation(1, 2); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(1, 2); + }, + { name: "ExpectationError" } + ); }); - it("throws when called with wrong args", function () { + it("throws when called with wrong args", function() { var expectation = this.expectation; expectation.withArgs(1, 2, 3); - assert.exception(function () { + assert.exception(function() { expectation(2, 2, 3); }, expectedException("ExpectationError")); }); - it("allows excessive args", function () { + it("allows excessive args", function() { var expectation = this.expectation; expectation.withArgs(1, 2, 3); - refute.exception(function () { + refute.exception(function() { expectation(1, 2, 3, 4); }); }); - it("calls accept with no args", function () { + it("calls accept with no args", function() { this.expectation.withArgs(); this.expectation(); assert(this.expectation.met()); }); - it("allows no args called with excessive args", function () { + it("allows no args called with excessive args", function() { var expectation = this.expectation; expectation.withArgs(); - refute.exception(function () { + refute.exception(function() { expectation(1, 2, 3); }); }); - it("works with sinon matchers", function () { + it("works with sinon matchers", function() { this.expectation.withArgs(sinonMatch.number, sinonMatch.string, sinonMatch.func); - this.expectation(1, "test", function () { return; }); + this.expectation(1, "test", function() { + return; + }); assert(this.expectation.met()); }); - it("throws when sinon matchers fail", function () { + it("throws when sinon matchers fail", function() { var expectation = this.expectation; this.expectation.withArgs(sinonMatch.number, sinonMatch.string, sinonMatch.func); - assert.exception(function () { - expectation(1, 2, 3); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(1, 2, 3); + }, + { name: "ExpectationError" } + ); }); }); - describe(".withExactArgs", function () { - it("returns expectation for chaining", function () { + describe(".withExactArgs", function() { + it("returns expectation for chaining", function() { assert.same(this.expectation.withExactArgs(1), this.expectation); }); - it("accepts call with expected args", function () { + it("accepts call with expected args", function() { this.expectation.withExactArgs(1, 2, 3); this.expectation(1, 2, 3); assert(this.expectation.met()); }); - it("throws when called without args", function () { + it("throws when called without args", function() { var expectation = this.expectation; expectation.withExactArgs(1, 2, 3); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("throws when called with too few args", function () { + it("throws when called with too few args", function() { var expectation = this.expectation; expectation.withExactArgs(1, 2, 3); - assert.exception(function () { - expectation(1, 2); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(1, 2); + }, + { name: "ExpectationError" } + ); }); - it("throws when called with wrong args", function () { + it("throws when called with wrong args", function() { var expectation = this.expectation; expectation.withExactArgs(1, 2, 3); - assert.exception(function () { - expectation(2, 2, 3); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(2, 2, 3); + }, + { name: "ExpectationError" } + ); }); - it("should not allow excessive args", function () { + it("should not allow excessive args", function() { var expectation = this.expectation; expectation.withExactArgs(1, 2, 3); - assert.exception(function () { - expectation(1, 2, 3, 4); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(1, 2, 3, 4); + }, + { name: "ExpectationError" } + ); }); - it("accepts call with no expected args", function () { + it("accepts call with no expected args", function() { this.expectation.withExactArgs(); this.expectation(); assert(this.expectation.met()); }); - it("does not allow excessive args with no expected args", function () { + it("does not allow excessive args with no expected args", function() { var expectation = this.expectation; expectation.withExactArgs(); - assert.exception(function () { - expectation(1, 2, 3); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(1, 2, 3); + }, + { name: "ExpectationError" } + ); }); }); - describe(".on", function () { - it("returns expectation for chaining", function () { + describe(".on", function() { + it("returns expectation for chaining", function() { assert.same(this.expectation.on({}), this.expectation); }); - it("allows calls on object", function () { + it("allows calls on object", function() { this.expectation.on(this); this.expectation(); assert(this.expectation.met()); }); - it("throws if called on wrong object", function () { + it("throws if called on wrong object", function() { var expectation = this.expectation; expectation.on({}); - assert.exception(function () { - expectation(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation(); + }, + { name: "ExpectationError" } + ); }); - it("throws if calls on wrong Symbol", function () { + it("throws if calls on wrong Symbol", function() { if (typeof Symbol === "function") { var expectation = sinonExpectation.create("method"); expectation.on(Symbol()); - assert.exception(function () { - expectation.call(Symbol()); - }, function (err) { - return err.message === "method called with Symbol() as thisValue, expected Symbol()"; - }); + assert.exception( + function() { + expectation.call(Symbol()); + }, + function(err) { + return err.message === "method called with Symbol() as thisValue, expected Symbol()"; + } + ); } }); }); - describe(".verify", function () { - it("pass if met", function () { + describe(".verify", function() { + it("pass if met", function() { sinonStub(sinonExpectation, "pass"); var expectation = this.expectation; @@ -685,19 +788,22 @@ describe("sinonMock", function () { sinonExpectation.pass.restore(); }); - it("throws if not called enough times", function () { + it("throws if not called enough times", function() { var expectation = this.expectation; - assert.exception(function () { - expectation.verify(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + expectation.verify(); + }, + { name: "ExpectationError" } + ); }); - it("throws readable error", function () { + it("throws readable error", function() { var expectation = this.expectation; assert.exception( - function () { + function() { expectation.verify(); }, { @@ -708,14 +814,16 @@ describe("sinonMock", function () { }); }); - describe(".verify", function () { - beforeEach(function () { - this.method = function () { return; }; + describe(".verify", function() { + beforeEach(function() { + this.method = function() { + return; + }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); }); - it("restores mocks", function () { + it("restores mocks", function() { this.object.method(); this.object.method.call(this.thisValue); this.mock.verify(); @@ -723,7 +831,7 @@ describe("sinonMock", function () { assert.same(this.object.method, this.method); }); - it("passes verified mocks", function () { + it("passes verified mocks", function() { sinonStub(sinonExpectation, "pass"); this.mock.expects("method").once(); @@ -734,39 +842,47 @@ describe("sinonMock", function () { sinonExpectation.pass.restore(); }); - it("restores if not met", function () { + it("restores if not met", function() { var mock = this.mock; mock.expects("method"); - assert.exception(function () { - mock.verify(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + mock.verify(); + }, + { name: "ExpectationError" } + ); assert.same(this.object.method, this.method); }); - it("includes all calls in error message", function () { + it("includes all calls in error message", function() { var mock = this.mock; mock.expects("method").thrice(); - mock.expects("method").once().withArgs(42); + mock.expects("method") + .once() + .withArgs(42); assert.exception( - function () { + function() { mock.verify(); }, { - message: "Expected method([...]) thrice (never called)\n" + - "Expected method(42[, ...]) once (never called)" + message: + "Expected method([...]) thrice (never called)\n" + + "Expected method(42[, ...]) once (never called)" } ); }); - it("includes exact expected arguments in error message", function () { + it("includes exact expected arguments in error message", function() { var mock = this.mock; - mock.expects("method").once().withExactArgs(42); + mock.expects("method") + .once() + .withExactArgs(42); assert.exception( - function () { + function() { mock.verify(); }, { @@ -775,13 +891,15 @@ describe("sinonMock", function () { ); }); - it("includes received call count in error message", function () { + it("includes received call count in error message", function() { var mock = this.mock; - mock.expects("method").thrice().withExactArgs(42); + mock.expects("method") + .thrice() + .withExactArgs(42); this.object.method(42); assert.exception( - function () { + function() { mock.verify(); }, { @@ -790,67 +908,76 @@ describe("sinonMock", function () { ); }); - it("includes unexpected calls in error message", function () { + it("includes unexpected calls in error message", function() { var mock = this.mock; var object = this.object; - mock.expects("method").thrice().withExactArgs(42); + mock.expects("method") + .thrice() + .withExactArgs(42); assert.exception( - function () { + function() { object.method(); }, { - message: "Unexpected call: method()\n" + - " Expected method(42) thrice (never called)" + message: "Unexpected call: method()\n" + " Expected method(42) thrice (never called)" } ); }); - it("includes met expectations in error message", function () { + it("includes met expectations in error message", function() { var mock = this.mock; var object = this.object; - mock.expects("method").once().withArgs(1); - mock.expects("method").thrice().withExactArgs(42); + mock.expects("method") + .once() + .withArgs(1); + mock.expects("method") + .thrice() + .withExactArgs(42); object.method(1); assert.exception( - function () { + function() { object.method(); }, { - message: "Unexpected call: method()\n" + - " Expectation met: method(1[, ...]) once\n" + - " Expected method(42) thrice (never called)" + message: + "Unexpected call: method()\n" + + " Expectation met: method(1[, ...]) once\n" + + " Expected method(42) thrice (never called)" } ); }); - it("includes met expectations in error message from verify", function () { + it("includes met expectations in error message from verify", function() { var mock = this.mock; - mock.expects("method").once().withArgs(1); - mock.expects("method").thrice().withExactArgs(42); + mock.expects("method") + .once() + .withArgs(1); + mock.expects("method") + .thrice() + .withExactArgs(42); this.object.method(1); assert.exception( - function () { + function() { mock.verify(); }, { - message: "Expected method(42) thrice (never called)\n" + - "Expectation met: method(1[, ...]) once" + message: "Expected method(42) thrice (never called)\n" + "Expectation met: method(1[, ...]) once" } ); }); - it("reports min calls in error message", function () { + it("reports min calls in error message", function() { var mock = this.mock; mock.expects("method").atLeast(1); assert.exception( - function () { + function() { mock.verify(); }, { @@ -859,52 +986,56 @@ describe("sinonMock", function () { ); }); - it("reports max calls in error message", function () { + it("reports max calls in error message", function() { var mock = this.mock; var object = this.object; mock.expects("method").atMost(2); assert.exception( - function () { + function() { object.method(); object.method(); object.method(); }, { - message: "Unexpected call: method()\n" + - " Expectation met: method([...]) at most twice" + message: "Unexpected call: method()\n" + " Expectation met: method([...]) at most twice" } ); }); - it("reports min calls in met expectation", function () { + it("reports min calls in met expectation", function() { var mock = this.mock; var object = this.object; mock.expects("method").atLeast(1); - mock.expects("method").withArgs(2).once(); + mock.expects("method") + .withArgs(2) + .once(); assert.exception( - function () { + function() { object.method(); object.method(2); object.method(2); }, { - message: "Unexpected call: method(2)\n" + - " Expectation met: method([...]) at least once\n" + - " Expectation met: method(2[, ...]) once" + message: + "Unexpected call: method(2)\n" + + " Expectation met: method([...]) at least once\n" + + " Expectation met: method(2[, ...]) once" } ); }); - it("reports max and min calls in error messages", function () { + it("reports max and min calls in error messages", function() { var mock = this.mock; - mock.expects("method").atLeast(1).atMost(2); + mock.expects("method") + .atLeast(1) + .atMost(2); assert.exception( - function () { + function() { mock.verify(); }, { @@ -913,7 +1044,7 @@ describe("sinonMock", function () { ); }); - it("fails even if the original expectation exception was caught", function () { + it("fails even if the original expectation exception was caught", function() { var mock = this.mock; var object = this.object; @@ -921,16 +1052,19 @@ describe("sinonMock", function () { object.method(); - assert.exception(function () { + assert.exception(function() { object.method(); }); - assert.exception(function () { - mock.verify(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + mock.verify(); + }, + { name: "ExpectationError" } + ); }); - it("does not call pass if no expectations", function () { + it("does not call pass if no expectations", function() { var pass = sinonStub(sinonExpectation, "pass"); var mock = this.mock; @@ -945,18 +1079,20 @@ describe("sinonMock", function () { }); }); - describe(".usingPromise", function () { - beforeEach(function () { - this.method = function () { return; }; + describe(".usingPromise", function() { + beforeEach(function() { + this.method = function() { + return; + }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); }); - it("must be a function", function () { + it("must be a function", function() { assert.isFunction(this.mock.usingPromise); }); - it("must return the mock", function () { + it("must return the mock", function() { var mockPromise = {}; var actual = this.mock.usingPromise(mockPromise); @@ -964,8 +1100,10 @@ describe("sinonMock", function () { assert.same(actual, this.mock); }); - it("must set all expectations with mockPromise", function () { - if (!global.Promise) { return this.skip(); } + it("must set all expectations with mockPromise", function() { + if (!global.Promise) { + return this.skip(); + } var resolveValue = {}; var mockPromise = { @@ -975,137 +1113,156 @@ describe("sinonMock", function () { this.mock.usingPromise(mockPromise); this.mock.expects("method").resolves({}); - return this.object.method() - .then(function (action) { - - assert.same(resolveValue, action); - assert(mockPromise.resolve.calledOnce); - }); + return this.object.method().then(function(action) { + assert.same(resolveValue, action); + assert(mockPromise.resolve.calledOnce); + }); }); }); - describe("mock object", function () { - beforeEach(function () { - this.method = function () { return; }; + describe("mock object", function() { + beforeEach(function() { + this.method = function() { + return; + }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); }); - it("mocks object method", function () { + it("mocks object method", function() { this.mock.expects("method"); assert.isFunction(this.object.method); refute.same(this.object.method, this.method); }); - it("reverts mocked method", function () { + it("reverts mocked method", function() { this.mock.expects("method"); this.object.method.restore(); assert.same(this.object.method, this.method); }); - it("reverts expectation", function () { + it("reverts expectation", function() { this.mock.expects("method"); this.object.method.restore(); assert.same(this.object.method, this.method); }); - it("reverts mock", function () { + it("reverts mock", function() { this.mock.expects("method"); this.mock.restore(); assert.same(this.object.method, this.method); }); - it("verifies mock", function () { + it("verifies mock", function() { this.mock.expects("method"); this.object.method(); var mock = this.mock; - refute.exception(function () { + refute.exception(function() { assert(mock.verify()); }); }); - it("verifies mock with unmet expectations", function () { + it("verifies mock with unmet expectations", function() { this.mock.expects("method"); var mock = this.mock; - assert.exception(function () { - assert(mock.verify()); - }, {name: "ExpectationError"}); + assert.exception( + function() { + assert(mock.verify()); + }, + { name: "ExpectationError" } + ); }); }); - describe("mock method multiple times", function () { - beforeEach(function () { + describe("mock method multiple times", function() { + beforeEach(function() { this.thisValue = {}; - this.method = function () { return; }; + this.method = function() { + return; + }; this.object = { method: this.method }; this.mock = sinonMock.create(this.object); this.mock.expects("method"); this.mock.expects("method").on(this.thisValue); }); - it("queues expectations", function () { + it("queues expectations", function() { var object = this.object; - refute.exception(function () { + refute.exception(function() { object.method(); }); }); - it("starts on next expectation when first is met", function () { + it("starts on next expectation when first is met", function() { var object = this.object; object.method(); - assert.exception(function () { - object.method(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + object.method(); + }, + { name: "ExpectationError" } + ); }); - it("fails on last expectation", function () { + it("fails on last expectation", function() { var object = this.object; object.method(); object.method.call(this.thisValue); - assert.exception(function () { - object.method(); - }, {name: "ExpectationError"}); + assert.exception( + function() { + object.method(); + }, + { name: "ExpectationError" } + ); }); - it("allows mock calls in any order", function () { - var object = { method: function () { return; } }; + it("allows mock calls in any order", function() { + var object = { + method: function() { + return; + } + }; var mock = sinonMock(object); - mock.expects("method").once().withArgs(42); - mock.expects("method").twice().withArgs("Yeah"); - - refute.exception(function () { + mock.expects("method") + .once() + .withArgs(42); + mock.expects("method") + .twice() + .withArgs("Yeah"); + + refute.exception(function() { object.method("Yeah"); }); - refute.exception(function () { + refute.exception(function() { object.method(42); }); - assert.exception(function () { + assert.exception(function() { object.method(1); }); - refute.exception(function () { + refute.exception(function() { object.method("Yeah"); }); - assert.exception(function () { + assert.exception(function() { object.method(42); }); }); }); - describe("mock function", function () { - it("returns mock method", function () { + describe("mock function", function() { + it("returns mock method", function() { var mock = sinonMock(); assert.isFunction(mock); @@ -1113,7 +1270,7 @@ describe("sinonMock", function () { assert.isFunction(mock.verify); }); - it("returns mock object", function () { + it("returns mock object", function() { var mock = sinonMock({}); assert.isObject(mock); @@ -1122,8 +1279,8 @@ describe("sinonMock", function () { }); }); - describe(".yields", function () { - it("invokes only argument as callback", function () { + describe(".yields", function() { + it("invokes only argument as callback", function() { var mock = sinonMock().yields(); var spy = sinonSpy(); mock(spy); @@ -1132,7 +1289,7 @@ describe("sinonMock", function () { assert.equals(spy.args[0].length, 0); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var mock = sinonMock().yields(); assert.exception(mock, { diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 982d533cc..6c4265469 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -28,50 +28,55 @@ if (!assert.stub) { } referee.add("fakeServerWithClock", { - assert: function (obj, expected) { - return samsam.deepEqual(obj, expected) && - fakeServer.create.calledOn(fakeServerWithClock); + assert: function(obj, expected) { + return samsam.deepEqual(obj, expected) && fakeServer.create.calledOn(fakeServerWithClock); }, assertMessage: "Expected object ${0} to be a fake server with clock" }); -describe("Sandbox", function () { - function noop() { return; } +describe("Sandbox", function() { + function noop() { + return; + } - it("exposes match", function () { + it("exposes match", function() { var sandbox = new Sandbox(); assert.same(sandbox.match, sinonMatch); }); - it("exposes assert", function () { + it("exposes assert", function() { var sandbox = new Sandbox(); assert.same(sandbox.assert, sinonAssert); }); - it("can be reset without failing when pre-configured to use a fake server", function () { - var sandbox = createSandbox({useFakeServer: true}); - refute.exception(function () { + it("can be reset without failing when pre-configured to use a fake server", function() { + var sandbox = createSandbox({ useFakeServer: true }); + refute.exception(function() { sandbox.reset(); }); }); - it("can be reset without failing when configured to use a fake server", function () { + it("can be reset without failing when configured to use a fake server", function() { var sandbox = new Sandbox(); sandbox.useFakeServer(); - refute.exception(function () { + refute.exception(function() { sandbox.reset(); }); }); - describe(".mock", function () { - beforeEach(function () { + describe(".mock", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("returns a mock", function () { - var object = { method: function () { return; }}; + it("returns a mock", function() { + var object = { + method: function() { + return; + } + }; var actual = this.sandbox.mock(object); actual.expects("method"); @@ -80,15 +85,19 @@ describe("Sandbox", function () { assert.equals(typeof object.method.restore, "function"); }); - it("adds mock to fake array", function () { + it("adds mock to fake array", function() { var fakes = this.sandbox.getFakes(); - var object = { method: function () { return; }}; + var object = { + method: function() { + return; + } + }; var expected = this.sandbox.mock(object); assert(fakes.indexOf(expected) !== -1); }); - it("appends mocks to fake array", function () { + it("appends mocks to fake array", function() { var fakes = this.sandbox.getFakes(); this.sandbox.mock({}); @@ -98,23 +107,37 @@ describe("Sandbox", function () { }); }); - describe("stub and mock test", function () { - beforeEach(function () { + describe("stub and mock test", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("appends mocks and stubs to fake array", function () { + it("appends mocks and stubs to fake array", function() { var fakes = this.sandbox.getFakes(); - this.sandbox.mock({ method: function () { return; } }, "method"); - this.sandbox.stub({ method: function () { return; } }, "method"); + this.sandbox.mock( + { + method: function() { + return; + } + }, + "method" + ); + this.sandbox.stub( + { + method: function() { + return; + } + }, + "method" + ); assert.equals(fakes.length, 2); }); }); - describe(".spy", function () { - it("should return a spy", function () { + describe(".spy", function() { + it("should return a spy", function() { var sandbox = createSandbox(); var spy = sandbox.spy(); @@ -122,7 +145,7 @@ describe("Sandbox", function () { assert.equals(spy.displayName, "spy"); }); - it("should add a spy to the internal collection", function () { + it("should add a spy to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -133,25 +156,29 @@ describe("Sandbox", function () { }); }); - describe(".createStubInstance", function () { - beforeEach(function () { + describe(".createStubInstance", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("stubs existing methods", function () { - var Class = function () { return; }; - Class.prototype.method = function () { return; }; + it("stubs existing methods", function() { + var Class = function() { + return; + }; + Class.prototype.method = function() { + return; + }; var stub = this.sandbox.createStubInstance(Class); stub.method.returns(3); assert.equals(3, stub.method()); }); - it("should require a function", function () { + it("should require a function", function() { var sandbox = this.sandbox; assert.exception( - function () { + function() { sandbox.createStubInstance("not a function"); }, { @@ -161,11 +188,19 @@ describe("Sandbox", function () { ); }); - it("resets all stub methods on reset()", function () { - var Class = function () { return; }; - Class.prototype.method1 = function () { return; }; - Class.prototype.method2 = function () { return; }; - Class.prototype.method3 = function () { return; }; + it("resets all stub methods on reset()", function() { + var Class = function() { + return; + }; + Class.prototype.method1 = function() { + return; + }; + Class.prototype.method2 = function() { + return; + }; + Class.prototype.method3 = function() { + return; + }; var stub = this.sandbox.createStubInstance(Class); stub.method1.returns(1); @@ -180,44 +215,52 @@ describe("Sandbox", function () { assert.equals(undefined, stub.method3()); }); - it("doesn't stub fake methods", function () { - var Class = function () { return; }; + it("doesn't stub fake methods", function() { + var Class = function() { + return; + }; var stub = this.sandbox.createStubInstance(Class); - assert.exception(function () { + assert.exception(function() { stub.method.returns(3); }); }); - it("doesn't call the constructor", function () { - var Class = function (a, b) { + it("doesn't call the constructor", function() { + var Class = function(a, b) { var c = a + b; throw c; }; - Class.prototype.method = function () { return; }; + Class.prototype.method = function() { + return; + }; var stub = this.sandbox.createStubInstance(Class); - refute.exception(function () { + refute.exception(function() { stub.method(3); }); }); - it("retains non function values", function () { + it("retains non function values", function() { var TYPE = "some-value"; - var Class = function () { return; }; + var Class = function() { + return; + }; Class.prototype.type = TYPE; var stub = this.sandbox.createStubInstance(Class); assert.equals(TYPE, stub.type); }); - it("has no side effects on the prototype", function () { + it("has no side effects on the prototype", function() { var proto = { - method: function () { + method: function() { throw new Error("error"); } }; - var Class = function () { return; }; + var Class = function() { + return; + }; Class.prototype = proto; var stub = this.sandbox.createStubInstance(Class); @@ -225,29 +268,29 @@ describe("Sandbox", function () { assert.exception(proto.method); }); - it("throws exception for non function params", function () { + it("throws exception for non function params", function() { var types = [{}, 3, "hi!"]; for (var i = 0; i < types.length; i++) { // yes, it's silly to create functions in a loop, it's also a test /* eslint-disable-next-line ie11/no-loop-func, no-loop-func */ - assert.exception(function () { + assert.exception(function() { this.sandbox.createStubInstance(types[i]); }); } }); }); - describe(".stub", function () { - beforeEach(function () { + describe(".stub", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("fails if stubbing property on null", function () { + it("fails if stubbing property on null", function() { var sandbox = this.sandbox; assert.exception( - function () { + function() { sandbox.stub(null, "prop"); }, { @@ -256,12 +299,12 @@ describe("Sandbox", function () { ); }); - it("fails if stubbing symbol on null", function () { + it("fails if stubbing symbol on null", function() { if (typeof Symbol === "function") { var sandbox = this.sandbox; assert.exception( - function () { + function() { sandbox.stub(null, Symbol()); }, { @@ -271,37 +314,65 @@ describe("Sandbox", function () { } }); - it("creates a stub", function () { - var object = { method: function () { return; } }; + it("creates a stub", function() { + var object = { + method: function() { + return; + } + }; this.sandbox.stub(object, "method"); assert.equals(typeof object.method.restore, "function"); }); - it("adds stub to fake array", function () { + it("adds stub to fake array", function() { var fakes = this.sandbox.getFakes(); - var object = { method: function () { return; } }; + var object = { + method: function() { + return; + } + }; var stub = this.sandbox.stub(object, "method"); assert.isTrue(fakes.indexOf(stub) !== -1); }); - it("appends stubs to fake array", function () { + it("appends stubs to fake array", function() { var fakes = this.sandbox.getFakes(); - this.sandbox.stub({ method: function () { return; } }, "method"); - this.sandbox.stub({ method: function () { return; } }, "method"); + this.sandbox.stub( + { + method: function() { + return; + } + }, + "method" + ); + this.sandbox.stub( + { + method: function() { + return; + } + }, + "method" + ); assert.equals(fakes.length, 2); }); - it("adds all object methods to fake array", function () { + it("adds all object methods to fake array", function() { var fakes = this.sandbox.getFakes(); var object = { - method: function () { return; }, - method2: function () { return; }, - method3: function () { return; } + method: function() { + return; + }, + method2: function() { + return; + }, + method3: function() { + return; + } }; Object.defineProperty(object, "method3", { @@ -316,25 +387,35 @@ describe("Sandbox", function () { assert.equals(fakes.length, 3); }); - it("returns a stubbed object", function () { - var object = { method: function () { return; } }; + it("returns a stubbed object", function() { + var object = { + method: function() { + return; + } + }; assert.equals(this.sandbox.stub(object), object); }); - it("returns a stubbed method", function () { - var object = { method: function () { return; } }; + it("returns a stubbed method", function() { + var object = { + method: function() { + return; + } + }; assert.equals(this.sandbox.stub(object, "method"), object.method); }); if (typeof process !== "undefined") { - describe("on node", function () { - beforeEach(function () { + describe("on node", function() { + beforeEach(function() { process.env.HELL = "Ain't too bad"; }); - it("stubs environment property", function () { + it("stubs environment property", function() { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () { return; }; + deprecated.printWarning = function() { + return; + }; this.sandbox.stub(process.env, "HELL").value("froze over"); assert.equals(process.env.HELL, "froze over"); @@ -345,15 +426,17 @@ describe("Sandbox", function () { } }); - describe("stub anything", function () { - beforeEach(function () { + describe("stub anything", function() { + beforeEach(function() { this.object = { property: 42 }; this.sandbox = new Sandbox(); }); - it("stubs number property", function () { + it("stubs number property", function() { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () { return; }; + deprecated.printWarning = function() { + return; + }; this.sandbox.stub(this.object, "property").value(1); @@ -362,9 +445,11 @@ describe("Sandbox", function () { deprecated.printWarning = originalPrintWarning; }); - it("restores number property", function () { + it("restores number property", function() { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () { return; }; + deprecated.printWarning = function() { + return; + }; this.sandbox.stub(this.object, "property").value(1); this.sandbox.restore(); @@ -374,39 +459,47 @@ describe("Sandbox", function () { deprecated.printWarning = originalPrintWarning; }); - it("fails if property does not exist", function () { + it("fails if property does not exist", function() { var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () { return; }; + deprecated.printWarning = function() { + return; + }; var sandbox = this.sandbox; var object = {}; - assert.exception(function () { + assert.exception(function() { sandbox.stub(object, "prop", 1); }); deprecated.printWarning = originalPrintWarning; }); - it("fails if Symbol does not exist", function () { + it("fails if Symbol does not exist", function() { if (typeof Symbol === "function") { var sandbox = this.sandbox; var object = {}; var originalPrintWarning = deprecated.printWarning; - deprecated.printWarning = function () { return; }; + deprecated.printWarning = function() { + return; + }; - assert.exception(function () { - sandbox.stub(object, Symbol()); - }, {message: "Cannot stub non-existent own property Symbol()"}, TypeError); + assert.exception( + function() { + sandbox.stub(object, Symbol()); + }, + { message: "Cannot stub non-existent own property Symbol()" }, + TypeError + ); deprecated.printWarning = originalPrintWarning; } }); }); - describe(".fake", function () { - it("should return a fake", function () { + describe(".fake", function() { + it("should return a fake", function() { var sandbox = createSandbox(); var fake = sandbox.fake(); @@ -414,7 +507,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake to the internal collection", function () { + it("should add a fake to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -424,8 +517,8 @@ describe("Sandbox", function () { assert.isTrue(fakes.indexOf(expected) !== -1); }); - describe(".returns", function () { - it("should return a fake behavior", function () { + describe(".returns", function() { + it("should return a fake behavior", function() { var sandbox = createSandbox(); var fake = sandbox.fake.returns(); @@ -433,7 +526,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake behavior to the internal collection", function () { + it("should add a fake behavior to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -444,8 +537,8 @@ describe("Sandbox", function () { }); }); - describe(".throws", function () { - it("should return a fake behavior", function () { + describe(".throws", function() { + it("should return a fake behavior", function() { var sandbox = createSandbox(); var fake = sandbox.fake.throws(); @@ -453,7 +546,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake behavior to the internal collection", function () { + it("should add a fake behavior to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -464,8 +557,8 @@ describe("Sandbox", function () { }); }); - describe(".resolves", function () { - it("should return a fake behavior", function () { + describe(".resolves", function() { + it("should return a fake behavior", function() { var sandbox = createSandbox(); var fake = sandbox.fake.resolves(); @@ -473,7 +566,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake behavior to the internal collection", function () { + it("should add a fake behavior to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -484,8 +577,8 @@ describe("Sandbox", function () { }); }); - describe(".rejects", function () { - it("should return a fake behavior", function () { + describe(".rejects", function() { + it("should return a fake behavior", function() { var sandbox = createSandbox(); var fake = sandbox.fake.rejects(); @@ -493,7 +586,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake behavior to the internal collection", function () { + it("should add a fake behavior to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -504,8 +597,8 @@ describe("Sandbox", function () { }); }); - describe(".yields", function () { - it("should return a fake behavior", function () { + describe(".yields", function() { + it("should return a fake behavior", function() { var sandbox = createSandbox(); var fake = sandbox.fake.yields(); @@ -513,7 +606,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake behavior to the internal collection", function () { + it("should add a fake behavior to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -524,8 +617,8 @@ describe("Sandbox", function () { }); }); - describe(".yieldsAsync", function () { - it("should return a fake behavior", function () { + describe(".yieldsAsync", function() { + it("should return a fake behavior", function() { var sandbox = createSandbox(); var fake = sandbox.fake.yieldsAsync(); @@ -533,7 +626,7 @@ describe("Sandbox", function () { assert.equals(fake.displayName, "fake"); }); - it("should add a fake behavior to the internal collection", function () { + it("should add a fake behavior to the internal collection", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); var expected; @@ -545,12 +638,12 @@ describe("Sandbox", function () { }); }); - describe(".verifyAndRestore", function () { - beforeEach(function () { + describe(".verifyAndRestore", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("calls verify and restore", function () { + it("calls verify and restore", function() { this.sandbox.verify = sinonSpy(); this.sandbox.restore = sinonSpy(); @@ -560,22 +653,22 @@ describe("Sandbox", function () { assert(this.sandbox.restore.called); }); - it("throws when restore throws", function () { + it("throws when restore throws", function() { this.sandbox.verify = sinonSpy(); this.sandbox.restore = sinonStub().throws(); - assert.exception(function () { + assert.exception(function() { this.sandbox.verifyAndRestore(); }); }); - it("calls restore when restore throws", function () { + it("calls restore when restore throws", function() { var sandbox = this.sandbox; sandbox.verify = sinonSpy(); sandbox.restore = sinonStub().throws(); - assert.exception(function () { + assert.exception(function() { sandbox.verifyAndRestore(); }); @@ -583,14 +676,18 @@ describe("Sandbox", function () { }); }); - describe(".replace", function () { - beforeEach(function () { + describe(".replace", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("should replace a function property", function () { - var replacement = function replacement() { return; }; - var existing = function existing() { return; }; + it("should replace a function property", function() { + var replacement = function replacement() { + return; + }; + var existing = function existing() { + return; + }; var object = { property: existing }; @@ -604,7 +701,7 @@ describe("Sandbox", function () { assert.equals(object.property, existing); }); - it("should replace a non-function property", function () { + it("should replace a non-function property", function() { var replacement = "replacement"; var existing = "existing"; var object = { @@ -620,7 +717,7 @@ describe("Sandbox", function () { assert.equals(object.property, existing); }); - it("should replace an inherited property", function () { + it("should replace an inherited property", function() { var replacement = "replacement"; var existing = "existing"; var object = Object.create({ @@ -636,11 +733,11 @@ describe("Sandbox", function () { assert.equals(object.property, existing); }); - it("should error on missing descriptor", function () { + it("should error on missing descriptor", function() { var sandbox = this.sandbox; assert.exception( - function () { + function() { sandbox.replace({}, "i-dont-exist"); }, { @@ -650,14 +747,14 @@ describe("Sandbox", function () { ); }); - it("should error on missing replacement", function () { + it("should error on missing replacement", function() { var sandbox = this.sandbox; var object = Object.create({ property: "catpants" }); assert.exception( - function () { + function() { sandbox.replace(object, "property"); }, { @@ -667,49 +764,60 @@ describe("Sandbox", function () { ); }); - it("should refuse to replace a non-function with a function", function () { + it("should refuse to replace a non-function with a function", function() { var sandbox = this.sandbox; - var replacement = function () { return "replacement"; }; + var replacement = function() { + return "replacement"; + }; var existing = "existing"; var object = { property: existing }; - assert.exception(function () { - sandbox.replace(object, "property", replacement); - }, {message: "Cannot replace string with function"}); + assert.exception( + function() { + sandbox.replace(object, "property", replacement); + }, + { message: "Cannot replace string with function" } + ); }); - it("should refuse to replace a function with a non-function", function () { + it("should refuse to replace a function with a non-function", function() { var sandbox = this.sandbox; var replacement = "replacement"; var object = { - property: function () { + property: function() { return "apple pie"; } }; - assert.exception(function () { - sandbox.replace(object, "property", replacement); - }, {message: "Cannot replace function with string"}); + assert.exception( + function() { + sandbox.replace(object, "property", replacement); + }, + { message: "Cannot replace function with string" } + ); }); - it("should refuse to replace a fake twice", function () { + it("should refuse to replace a fake twice", function() { var sandbox = this.sandbox; var object = { - property: function () { + property: function() { return "apple pie"; } }; sandbox.replace(object, "property", sinonFake()); - assert.exception(function () { - sandbox.replace(object, "property", sinonFake()); - }, {message: "Attempted to replace property which is already replaced"}); + assert.exception( + function() { + sandbox.replace(object, "property", sinonFake()); + }, + { message: "Attempted to replace property which is already replaced" } + ); }); - it("should refuse to replace a string twice", function () { + it("should refuse to replace a string twice", function() { var sandbox = this.sandbox; var object = { property: "original" @@ -717,12 +825,15 @@ describe("Sandbox", function () { sandbox.replace(object, "property", "first"); - assert.exception(function () { - sandbox.replace(object, "property", "second"); - }, {message: "Attempted to replace property which is already replaced"}); + assert.exception( + function() { + sandbox.replace(object, "property", "second"); + }, + { message: "Attempted to replace property which is already replaced" } + ); }); - it("should return the replacement argument", function () { + it("should return the replacement argument", function() { var replacement = "replacement"; var existing = "existing"; var object = { @@ -734,8 +845,8 @@ describe("Sandbox", function () { assert.equals(actual, replacement); }); - describe("when asked to replace a getter", function () { - it("should throw an Error", function () { + describe("when asked to replace a getter", function() { + it("should throw an Error", function() { var sandbox = this.sandbox; var object = { get foo() { @@ -743,14 +854,17 @@ describe("Sandbox", function () { } }; - assert.exception(function () { - sandbox.replace(object, "foo", sinonFake()); - }, {message: "Use sandbox.replaceGetter for replacing getters"}); + assert.exception( + function() { + sandbox.replace(object, "foo", sinonFake()); + }, + { message: "Use sandbox.replaceGetter for replacing getters" } + ); }); }); - describe("when asked to replace a setter", function () { - it("should throw an Error", function () { + describe("when asked to replace a setter", function() { + it("should throw an Error", function() { var sandbox = this.sandbox; // eslint-disable-next-line accessor-pairs var object = { @@ -759,19 +873,22 @@ describe("Sandbox", function () { } }; - assert.exception(function () { - sandbox.replace(object, "foo", sinonFake()); - }, {message: "Use sandbox.replaceSetter for replacing setters"}); + assert.exception( + function() { + sandbox.replace(object, "foo", sinonFake()); + }, + { message: "Use sandbox.replaceSetter for replacing setters" } + ); }); }); }); - describe(".replaceGetter", function () { - beforeEach(function () { + describe(".replaceGetter", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("should replace getters", function () { + it("should replace getters", function() { var expected = "baz"; var object = { get foo() { @@ -784,7 +901,7 @@ describe("Sandbox", function () { assert.equals(object.foo, expected); }); - it("should return replacement", function () { + it("should return replacement", function() { var replacement = sinonFake.returns("baz"); var object = { get foo() { @@ -797,7 +914,7 @@ describe("Sandbox", function () { assert.equals(actual, replacement); }); - it("should replace an inherited property", function () { + it("should replace an inherited property", function() { var expected = "baz"; var replacement = sinonFake.returns(expected); var existing = "existing"; @@ -816,11 +933,11 @@ describe("Sandbox", function () { assert.equals(object.foo, existing); }); - it("should error on missing descriptor", function () { + it("should error on missing descriptor", function() { var sandbox = this.sandbox; assert.exception( - function () { + function() { sandbox.replaceGetter({}, "i-dont-exist"); }, { @@ -830,14 +947,17 @@ describe("Sandbox", function () { ); }); - it("should error when descriptor has no getter", function () { + it("should error when descriptor has no getter", function() { var sandbox = this.sandbox; - var object = { // eslint-disable-line accessor-pairs - set catpants(_) { return; } + // eslint-disable-next-line accessor-pairs + var object = { + set catpants(_) { + return; + } }; assert.exception( - function () { + function() { sandbox.replaceGetter(object, "catpants", noop); }, { @@ -847,8 +967,8 @@ describe("Sandbox", function () { ); }); - describe("when called with a non-function replacement argument", function () { - it("should throw a TypeError", function () { + describe("when called with a non-function replacement argument", function() { + it("should throw a TypeError", function() { var sandbox = this.sandbox; var expected = "baz"; var object = { @@ -857,13 +977,16 @@ describe("Sandbox", function () { } }; - assert.exception(function () { - sandbox.replaceGetter(object, "foo", expected); - }, {message: "Expected replacement argument to be a function"}); + assert.exception( + function() { + sandbox.replaceGetter(object, "foo", expected); + }, + { message: "Expected replacement argument to be a function" } + ); }); }); - it("allows restoring getters", function () { + it("allows restoring getters", function() { var expected = "baz"; var object = { get foo() { @@ -878,7 +1001,7 @@ describe("Sandbox", function () { assert.equals(object.foo, "bar"); }); - it("should refuse to replace a getter twice", function () { + it("should refuse to replace a getter twice", function() { var sandbox = this.sandbox; var object = { get foo() { @@ -888,18 +1011,21 @@ describe("Sandbox", function () { sandbox.replaceGetter(object, "foo", sinonFake.returns("one")); - assert.exception(function () { - sandbox.replaceGetter(object, "foo", sinonFake.returns("two")); - }, {message: "Attempted to replace foo which is already replaced"}); + assert.exception( + function() { + sandbox.replaceGetter(object, "foo", sinonFake.returns("two")); + }, + { message: "Attempted to replace foo which is already replaced" } + ); }); }); - describe(".replaceSetter", function () { - beforeEach(function () { + describe(".replaceSetter", function() { + beforeEach(function() { this.sandbox = createSandbox(); }); - it("should replace setter", function () { + it("should replace setter", function() { // eslint-disable-next-line accessor-pairs var object = { set foo(value) { @@ -908,7 +1034,7 @@ describe("Sandbox", function () { prop: "bar" }; - this.sandbox.replaceSetter(object, "foo", function (val) { + this.sandbox.replaceSetter(object, "foo", function(val) { this.prop = val + "bla"; }); @@ -917,7 +1043,7 @@ describe("Sandbox", function () { assert.equals(object.prop, "blabla"); }); - it("should return replacement", function () { + it("should return replacement", function() { // eslint-disable-next-line accessor-pairs var object = { set foo(value) { @@ -925,7 +1051,7 @@ describe("Sandbox", function () { }, prop: "bar" }; - var replacement = function (val) { + var replacement = function(val) { this.prop = val + "bla"; }; var actual = this.sandbox.replaceSetter(object, "foo", replacement); @@ -933,7 +1059,7 @@ describe("Sandbox", function () { assert.equals(actual, replacement); }); - it("should replace an inherited property", function () { + it("should replace an inherited property", function() { // eslint-disable-next-line accessor-pairs var object = Object.create({ set foo(value) { @@ -941,7 +1067,7 @@ describe("Sandbox", function () { }, prop: "bar" }); - var replacement = function (value) { + var replacement = function(value) { this.prop = value + "blabla"; }; @@ -954,11 +1080,11 @@ describe("Sandbox", function () { assert.equals(object.prop, "doodle"); }); - it("should error on missing descriptor", function () { + it("should error on missing descriptor", function() { var sandbox = this.sandbox; assert.exception( - function () { + function() { sandbox.replaceSetter({}, "i-dont-exist"); }, { @@ -968,7 +1094,7 @@ describe("Sandbox", function () { ); }); - it("should error when descriptor has no setter", function () { + it("should error when descriptor has no setter", function() { var sandbox = this.sandbox; var object = { get catpants() { @@ -977,7 +1103,7 @@ describe("Sandbox", function () { }; assert.exception( - function () { + function() { sandbox.replaceSetter(object, "catpants", noop); }, { @@ -987,8 +1113,8 @@ describe("Sandbox", function () { ); }); - describe("when called with a non-function replacement argument", function () { - it("should throw a TypeError", function () { + describe("when called with a non-function replacement argument", function() { + it("should throw a TypeError", function() { var sandbox = this.sandbox; // eslint-disable-next-line accessor-pairs var object = { @@ -998,13 +1124,16 @@ describe("Sandbox", function () { prop: "bar" }; - assert.exception(function () { - sandbox.replaceSetter(object, "foo", "bla"); - }, {message: "Expected replacement argument to be a function"}); + assert.exception( + function() { + sandbox.replaceSetter(object, "foo", "bla"); + }, + { message: "Expected replacement argument to be a function" } + ); }); }); - it("allows restoring setters", function () { + it("allows restoring setters", function() { // eslint-disable-next-line accessor-pairs var object = { set foo(value) { @@ -1013,7 +1142,7 @@ describe("Sandbox", function () { prop: "bar" }; - this.sandbox.replaceSetter(object, "foo", function (val) { + this.sandbox.replaceSetter(object, "foo", function(val) { this.prop = val + "bla"; }); @@ -1024,24 +1153,29 @@ describe("Sandbox", function () { assert.equals(object.prop, "bla"); }); - it("should refuse to replace a setter twice", function () { + it("should refuse to replace a setter twice", function() { var sandbox = this.sandbox; // eslint-disable-next-line accessor-pairs var object = { - set foo(value) { return; } + set foo(value) { + return; + } }; sandbox.replaceSetter(object, "foo", sinonFake()); - assert.exception(function () { - sandbox.replaceSetter(object, "foo", sinonFake.returns("two")); - }, {message: "Attempted to replace foo which is already replaced"}); + assert.exception( + function() { + sandbox.replaceSetter(object, "foo", sinonFake.returns("two")); + }, + { message: "Attempted to replace foo which is already replaced" } + ); }); }); - describe(".reset", function () { - beforeEach(function () { - var sandbox = this.sandbox = createSandbox(); + describe(".reset", function() { + beforeEach(function() { + var sandbox = (this.sandbox = createSandbox()); var fakes = sandbox.getFakes(); fakes.push({ @@ -1054,7 +1188,7 @@ describe("Sandbox", function () { }); }); - it("calls reset on all fakes", function () { + it("calls reset on all fakes", function() { var fake0 = this.sandbox.getFakes()[0]; var fake1 = this.sandbox.getFakes()[1]; @@ -1064,7 +1198,7 @@ describe("Sandbox", function () { assert(fake1.reset.called); }); - it("calls resetHistory on all fakes", function () { + it("calls resetHistory on all fakes", function() { var fake0 = this.sandbox.getFakes()[0]; var fake1 = this.sandbox.getFakes()[1]; @@ -1074,7 +1208,7 @@ describe("Sandbox", function () { assert(fake1.resetHistory.called); }); - it("resets fake behaviours", function () { + it("resets fake behaviours", function() { var fake = this.sandbox.fake(); fake(1234); @@ -1084,16 +1218,16 @@ describe("Sandbox", function () { }); }); - describe(".resetBehavior", function () { - beforeEach(function () { - var sandbox = this.sandbox = createSandbox(); + describe(".resetBehavior", function() { + beforeEach(function() { + var sandbox = (this.sandbox = createSandbox()); var fakes = sandbox.getFakes(); - fakes.push({resetBehavior: sinonSpy()}); - fakes.push({resetBehavior: sinonSpy()}); + fakes.push({ resetBehavior: sinonSpy() }); + fakes.push({ resetBehavior: sinonSpy() }); }); - it("calls resetBehavior on all fakes", function () { + it("calls resetBehavior on all fakes", function() { var fake0 = this.sandbox.getFakes()[0]; var fake1 = this.sandbox.getFakes()[1]; @@ -1104,10 +1238,10 @@ describe("Sandbox", function () { }); }); - describe(".resetHistory", function () { - beforeEach(function () { - var sandbox = this.sandbox = createSandbox(); - var fakes = this.fakes = sandbox.getFakes(); + describe(".resetHistory", function() { + beforeEach(function() { + var sandbox = (this.sandbox = createSandbox()); + var fakes = (this.fakes = sandbox.getFakes()); var spy1 = sinonSpy(); spy1(); @@ -1118,7 +1252,7 @@ describe("Sandbox", function () { fakes.push(spy2); }); - it("resets the history on all fakes", function () { + it("resets the history on all fakes", function() { var fake0 = this.fakes[0]; var fake1 = this.fakes[1]; @@ -1128,7 +1262,7 @@ describe("Sandbox", function () { refute(fake1.called); }); - it("calls reset on fake that does not have a resetHistory", function () { + it("calls reset on fake that does not have a resetHistory", function() { noop.reset = function reset() { noop.reset.called = true; }; @@ -1141,48 +1275,48 @@ describe("Sandbox", function () { }); }); - describe(".useFakeTimers", function () { - beforeEach(function () { + describe(".useFakeTimers", function() { + beforeEach(function() { this.sandbox = new Sandbox(); }); - afterEach(function () { + afterEach(function() { this.sandbox.restore(); }); - it("returns clock object", function () { + it("returns clock object", function() { var clock = this.sandbox.useFakeTimers(); assert.isObject(clock); assert.isFunction(clock.tick); }); - it("exposes clock property", function () { + it("exposes clock property", function() { this.sandbox.useFakeTimers(); assert.isObject(this.sandbox.clock); assert.isFunction(this.sandbox.clock.tick); }); - it("uses restorable clock", function () { + it("uses restorable clock", function() { this.sandbox.useFakeTimers(); assert.clock(this.sandbox.clock); }); - it("passes arguments to sinon.useFakeTimers", function () { + it("passes arguments to sinon.useFakeTimers", function() { var useFakeTimersStub = sinonStub(sinonClock, "useFakeTimers").returns({}); - this.sandbox.useFakeTimers({toFake: ["Date", "setTimeout"]}); - this.sandbox.useFakeTimers({toFake: ["setTimeout", "clearTimeout", "setInterval"]}); + this.sandbox.useFakeTimers({ toFake: ["Date", "setTimeout"] }); + this.sandbox.useFakeTimers({ toFake: ["setTimeout", "clearTimeout", "setInterval"] }); - assert(useFakeTimersStub.calledWith({toFake: ["Date", "setTimeout"]})); - assert(useFakeTimersStub.calledWith({toFake: ["setTimeout", "clearTimeout", "setInterval"]})); + assert(useFakeTimersStub.calledWith({ toFake: ["Date", "setTimeout"] })); + assert(useFakeTimersStub.calledWith({ toFake: ["setTimeout", "clearTimeout", "setInterval"] })); useFakeTimersStub.restore(); }); - it("restores the fakeTimer clock created by the sandbox when the sandbox is restored", function () { + it("restores the fakeTimer clock created by the sandbox when the sandbox is restored", function() { var originalSetTimeout = setTimeout; this.sandbox.useFakeTimers(); @@ -1193,7 +1327,7 @@ describe("Sandbox", function () { assert.same(setTimeout, originalSetTimeout, "fakeTimers restored"); }); - it("restores spied fake timers when then sanddox is restored", function () { + it("restores spied fake timers when then sanddox is restored", function() { var originalSetTimeout = setTimeout; this.sandbox.useFakeTimers(); @@ -1205,20 +1339,20 @@ describe("Sandbox", function () { }); }); - describe(".usingPromise", function () { - beforeEach(function () { + describe(".usingPromise", function() { + beforeEach(function() { this.sandbox = new Sandbox(); }); - afterEach(function () { + afterEach(function() { this.sandbox.restore(); }); - it("must be a function", function () { + it("must be a function", function() { assert.isFunction(this.sandbox.usingPromise); }); - it("must return the sandbox", function () { + it("must return the sandbox", function() { var mockPromise = {}; var actual = this.sandbox.usingPromise(mockPromise); @@ -1226,8 +1360,10 @@ describe("Sandbox", function () { assert.same(actual, this.sandbox); }); - it("must set all stubs created from sandbox with mockPromise", function () { - if (!supportPromise) { return this.skip(); } + it("must set all stubs created from sandbox with mockPromise", function() { + if (!supportPromise) { + return this.skip(); + } var resolveValue = {}; var mockPromise = { @@ -1237,23 +1373,24 @@ describe("Sandbox", function () { this.sandbox.usingPromise(mockPromise); var stub = this.sandbox.stub().resolves(); - return stub() - .then(function (action) { - assert.same(resolveValue, action); - assert(mockPromise.resolve.calledOnce); - }); + return stub().then(function(action) { + assert.same(resolveValue, action); + assert(mockPromise.resolve.calledOnce); + }); }); // eslint-disable-next-line mocha/no-identical-title - it("must set all stubs created from sandbox with mockPromise", function () { - if (!supportPromise) { return this.skip(); } + it("must set all stubs created from sandbox with mockPromise", function() { + if (!supportPromise) { + return this.skip(); + } var resolveValue = {}; var mockPromise = { resolve: sinonStub.create().resolves(resolveValue) }; var stubbedObject = { - stubbedMethod: function () { + stubbedMethod: function() { return; } }; @@ -1262,23 +1399,23 @@ describe("Sandbox", function () { this.sandbox.stub(stubbedObject); stubbedObject.stubbedMethod.resolves({}); - return stubbedObject.stubbedMethod() - .then(function (action) { - - assert.same(resolveValue, action); - assert(mockPromise.resolve.calledOnce); - }); + return stubbedObject.stubbedMethod().then(function(action) { + assert.same(resolveValue, action); + assert(mockPromise.resolve.calledOnce); + }); }); - it("must set all mocks created from sandbox with mockPromise", function () { - if (!supportPromise) { return this.skip(); } + it("must set all mocks created from sandbox with mockPromise", function() { + if (!supportPromise) { + return this.skip(); + } var resolveValue = {}; var mockPromise = { resolve: sinonStub.create().resolves(resolveValue) }; var mockedObject = { - mockedMethod: function () { + mockedMethod: function() { return; } }; @@ -1287,29 +1424,31 @@ describe("Sandbox", function () { var mock = this.sandbox.mock(mockedObject); mock.expects("mockedMethod").resolves({}); - return mockedObject.mockedMethod() - .then(function (action) { - - assert.same(resolveValue, action); - assert(mockPromise.resolve.calledOnce); - }); + return mockedObject.mockedMethod().then(function(action) { + assert.same(resolveValue, action); + assert(mockPromise.resolve.calledOnce); + }); }); }); // These were not run in browsers before, as we were only testing in node if (typeof window !== "undefined") { - describe("fake XHR/server", function () { - describe(".useFakeXMLHttpRequest", function () { - beforeEach(function () { + describe("fake XHR/server", function() { + describe(".useFakeXMLHttpRequest", function() { + beforeEach(function() { this.sandbox = new Sandbox(); }); - afterEach(function () { + afterEach(function() { this.sandbox.restore(); }); - it("calls sinon.useFakeXMLHttpRequest", function () { - var stubXhr = { restore: function () { return; } }; + it("calls sinon.useFakeXMLHttpRequest", function() { + var stubXhr = { + restore: function() { + return; + } + }; this.sandbox.stub(fakeXhr, "useFakeXMLHttpRequest").returns(stubXhr); var returnedXhr = this.sandbox.useFakeXMLHttpRequest(); @@ -1318,21 +1457,29 @@ describe("Sandbox", function () { assert.equals(stubXhr, returnedXhr); }); - it("returns fake xhr object created by nise", function () { - this.sandbox.stub(fakeXhr, "useFakeXMLHttpRequest").returns({ restore: function () { return; } }); + it("returns fake xhr object created by nise", function() { + this.sandbox.stub(fakeXhr, "useFakeXMLHttpRequest").returns({ + restore: function() { + return; + } + }); this.sandbox.useFakeXMLHttpRequest(); assert(fakeXhr.useFakeXMLHttpRequest.called); }); - it("doesn't secretly use useFakeServer", function () { - this.sandbox.stub(fakeServer, "create").returns({ restore: function () { return; } }); + it("doesn't secretly use useFakeServer", function() { + this.sandbox.stub(fakeServer, "create").returns({ + restore: function() { + return; + } + }); this.sandbox.useFakeXMLHttpRequest(); assert(fakeServer.create.notCalled); }); - it("adds fake xhr to fake collection", function () { + it("adds fake xhr to fake collection", function() { this.sandbox.useFakeXMLHttpRequest(); this.sandbox.restore(); @@ -1341,48 +1488,48 @@ describe("Sandbox", function () { }); }); - describe(".useFakeServer", function () { - beforeEach(function () { + describe(".useFakeServer", function() { + beforeEach(function() { this.sandbox = new Sandbox(); }); - afterEach(function () { + afterEach(function() { this.sandbox.restore(); }); - it("returns server", function () { + it("returns server", function() { var server = this.sandbox.useFakeServer(); assert.isObject(server); assert.isFunction(server.restore); }); - it("exposes server property", function () { + it("exposes server property", function() { var server = this.sandbox.useFakeServer(); assert.same(this.sandbox.server, server); }); - it("creates server", function () { + it("creates server", function() { var server = this.sandbox.useFakeServer(); assert(fakeServer.isPrototypeOf(server)); }); - it("creates server without clock by default", function () { + it("creates server without clock by default", function() { var server = this.sandbox.useFakeServer(); refute(fakeServerWithClock.isPrototypeOf(server)); }); - it("creates server with clock", function () { + it("creates server with clock", function() { this.sandbox.serverPrototype = fakeServerWithClock; var server = this.sandbox.useFakeServer(); assert(fakeServerWithClock.isPrototypeOf(server)); }); - it("adds server to fake collection", function () { + it("adds server to fake collection", function() { this.sandbox.useFakeServer(); this.sandbox.restore(); @@ -1393,17 +1540,17 @@ describe("Sandbox", function () { }); } - describe(".inject", function () { - beforeEach(function () { + describe(".inject", function() { + beforeEach(function() { this.obj = {}; this.sandbox = new Sandbox(); }); - afterEach(function () { + afterEach(function() { this.sandbox.restore(); }); - it("injects spy, stub, mock", function () { + it("injects spy, stub, mock", function() { this.sandbox.inject(this.obj); assert.isFunction(this.obj.spy); @@ -1411,7 +1558,7 @@ describe("Sandbox", function () { assert.isFunction(this.obj.mock); }); - it("does not define clock, server and requests objects", function () { + it("does not define clock, server and requests objects", function() { this.sandbox.inject(this.obj); assert.isFalse("clock" in this.obj); @@ -1419,7 +1566,7 @@ describe("Sandbox", function () { assert.isFalse("requests" in this.obj); }); - it("defines clock when using fake time", function () { + it("defines clock when using fake time", function() { this.sandbox.useFakeTimers(); this.sandbox.inject(this.obj); @@ -1431,7 +1578,7 @@ describe("Sandbox", function () { assert.isFalse("requests" in this.obj); }); - it("should return object", function () { + it("should return object", function() { var injected = this.sandbox.inject({}); assert.isObject(injected); @@ -1439,9 +1586,8 @@ describe("Sandbox", function () { }); if (supportsAjax) { - describe("ajax options", function () { - - it("defines server and requests when using fake time", function () { + describe("ajax options", function() { + it("defines server and requests when using fake time", function() { this.sandbox.useFakeServer(); this.sandbox.inject(this.obj); @@ -1453,7 +1599,7 @@ describe("Sandbox", function () { assert.equals(this.obj.requests, []); }); - it("should define all possible fakes", function () { + it("should define all possible fakes", function() { this.sandbox.useFakeServer(); this.sandbox.useFakeTimers(); this.sandbox.inject(this.obj); @@ -1463,9 +1609,7 @@ describe("Sandbox", function () { this.sandbox.clock.tick(10); - var xhr = window.XMLHttpRequest ? - new XMLHttpRequest() : - new ActiveXObject("Microsoft.XMLHTTP"); //eslint-disable-line no-undef + var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); //eslint-disable-line no-undef assert.isFunction(this.obj.spy); assert.isFunction(this.obj.stub); @@ -1478,36 +1622,39 @@ describe("Sandbox", function () { } }); - describe(".verify", function () { - it("calls verify on all fakes", function () { + describe(".verify", function() { + it("calls verify on all fakes", function() { var sandbox = createSandbox(); var fakes = sandbox.getFakes(); - fakes.push({verify: sinonSpy()}); - fakes.push({verify: sinonSpy()}); + fakes.push({ verify: sinonSpy() }); + fakes.push({ verify: sinonSpy() }); sandbox.verify(); - fakes.forEach(function (f) { + fakes.forEach(function(f) { assert(f.verify.calledOnce); }); }); }); - describe(".restore", function () { - it("throws when passed arguments", function () { + describe(".restore", function() { + it("throws when passed arguments", function() { var sandbox = new Sandbox(); - assert.exception(function () { - sandbox.restore("args"); - }, { - message: "sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()" - }); + assert.exception( + function() { + sandbox.restore("args"); + }, + { + message: "sandbox.restore() does not take any parameters. Perhaps you meant stub.restore()" + } + ); }); }); - describe("configurable sandbox", function () { - beforeEach(function () { + describe("configurable sandbox", function() { + beforeEach(function() { this.requests = []; this.fakeServer = { requests: this.requests }; @@ -1515,16 +1662,18 @@ describe("Sandbox", function () { sinonStub(fakeServer, "create").returns(this.fakeServer); }); - afterEach(function () { + afterEach(function() { this.useFakeTimersSpy.restore(); fakeServer.create.restore(); }); - it("yields stub, mock as arguments", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["stub", "mock"] - })); + it("yields stub, mock as arguments", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["stub", "mock"] + }) + ); assert.equals(sandbox.args.length, 2); assert.stub(sandbox.args[0]()); @@ -1533,11 +1682,13 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("yields spy, stub, mock as arguments", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["spy", "stub", "mock"] - })); + it("yields spy, stub, mock as arguments", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["spy", "stub", "mock"] + }) + ); assert.spy(sandbox.args[0]()); assert.stub(sandbox.args[1]()); @@ -1546,12 +1697,14 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("does not yield server when not faking xhr", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["server", "stub", "mock"], - useFakeServer: false - })); + it("does not yield server when not faking xhr", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["server", "stub", "mock"], + useFakeServer: false + }) + ); assert.equals(sandbox.args.length, 2); assert.stub(sandbox.args[0]()); @@ -1560,15 +1713,19 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("does not inject properties if they are already present", function () { - var server = function () { return; }; + it("does not inject properties if they are already present", function() { + var server = function() { + return; + }; var clock = {}; var spy = false; - var object = { server: server, clock: clock, spy: spy}; - var sandbox = createSandbox(sinonConfig({ - properties: ["server", "clock", "spy"], - injectInto: object - })); + var object = { server: server, clock: clock, spy: spy }; + var sandbox = createSandbox( + sinonConfig({ + properties: ["server", "clock", "spy"], + injectInto: object + }) + ); assert.same(object.server, server); assert.same(object.clock, clock); @@ -1578,13 +1735,14 @@ describe("Sandbox", function () { }); if (supportsAjax) { - describe("ajax options", function () { - - it("yields server when faking xhr", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["server", "stub", "mock"] - })); + describe("ajax options", function() { + it("yields server when faking xhr", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["server", "stub", "mock"] + }) + ); assert.equals(sandbox.args.length, 3); assert.equals(sandbox.args[0], this.fakeServer); @@ -1594,25 +1752,27 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("uses serverWithClock when faking xhr", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["server"], - useFakeServer: fakeServerWithClock - })); + it("uses serverWithClock when faking xhr", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["server"], + useFakeServer: fakeServerWithClock + }) + ); assert.fakeServerWithClock(sandbox.args[0], this.fakeServer); sandbox.restore(); }); - it("uses fakeServer as the serverPrototype by default", function () { + it("uses fakeServer as the serverPrototype by default", function() { var sandbox = createSandbox(); assert.same(sandbox.serverPrototype, fakeServer); }); - it("uses configured implementation as the serverPrototype", function () { + it("uses configured implementation as the serverPrototype", function() { var sandbox = createSandbox({ useFakeServer: fakeServerWithClock }); @@ -1620,11 +1780,13 @@ describe("Sandbox", function () { assert.same(sandbox.serverPrototype, fakeServerWithClock); }); - it("yields clock when faking timers", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["server", "clock"] - })); + it("yields clock when faking timers", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["server", "clock"] + }) + ); assert.same(sandbox.args[0], this.fakeServer); assert.clock(sandbox.args[1]); @@ -1632,13 +1794,15 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("injects properties into object", function () { + it("injects properties into object", function() { var object = {}; - var sandbox = createSandbox(sinonConfig({ - properties: ["server", "clock"], - injectInto: object - })); + var sandbox = createSandbox( + sinonConfig({ + properties: ["server", "clock"], + injectInto: object + }) + ); assert.equals(sandbox.args.length, 0); assert.equals(object.server, this.fakeServer); @@ -1651,14 +1815,16 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("should inject server and clock when only enabling them", function () { + it("should inject server and clock when only enabling them", function() { var object = {}; - var sandbox = createSandbox(sinonConfig({ - injectInto: object, - useFakeTimers: true, - useFakeServer: true - })); + var sandbox = createSandbox( + sinonConfig({ + injectInto: object, + useFakeTimers: true, + useFakeServer: true + }) + ); assert.equals(sandbox.args.length, 0); assert.equals(object.server, this.fakeServer); @@ -1676,25 +1842,29 @@ describe("Sandbox", function () { // This is currently testing the internals of useFakeTimers, we could possibly change it to be based on // behavior. - it("fakes specified timers", function () { - var sandbox = createSandbox(sinonConfig({ - injectIntoThis: false, - properties: ["clock"], - useFakeTimers: {toFake: ["Date", "setTimeout"]} - })); + it("fakes specified timers", function() { + var sandbox = createSandbox( + sinonConfig({ + injectIntoThis: false, + properties: ["clock"], + useFakeTimers: { toFake: ["Date", "setTimeout"] } + }) + ); - assert(this.useFakeTimersSpy.calledWith({toFake: ["Date", "setTimeout"]})); + assert(this.useFakeTimersSpy.calledWith({ toFake: ["Date", "setTimeout"] })); sandbox.restore(); }); - it("injects sandbox", function () { + it("injects sandbox", function() { var object = {}; - var sandbox = createSandbox(sinonConfig({ - properties: ["sandbox", "spy"], - injectInto: object - })); + var sandbox = createSandbox( + sinonConfig({ + properties: ["sandbox", "spy"], + injectInto: object + }) + ); assert.equals(sandbox.args.length, 0); assert.isFunction(object.spy); @@ -1703,13 +1873,15 @@ describe("Sandbox", function () { sandbox.restore(); }); - it("injects match", function () { + it("injects match", function() { var object = {}; - var sandbox = createSandbox(sinonConfig({ - properties: ["match"], - injectInto: object - })); + var sandbox = createSandbox( + sinonConfig({ + properties: ["match"], + injectInto: object + }) + ); assert.same(object.match, sinonMatch); @@ -1717,27 +1889,27 @@ describe("Sandbox", function () { }); }); - describe("getters and setters", function () { - it("allows stubbing getters", function () { + describe("getters and setters", function() { + it("allows stubbing getters", function() { var object = { foo: "bar" }; var sandbox = new Sandbox(); - sandbox.stub(object, "foo").get(function () { + sandbox.stub(object, "foo").get(function() { return "baz"; }); assert.equals(object.foo, "baz"); }); - it("allows restoring getters", function () { + it("allows restoring getters", function() { var object = { foo: "bar" }; var sandbox = new Sandbox(); - sandbox.stub(object, "foo").get(function () { + sandbox.stub(object, "foo").get(function() { return "baz"; }); @@ -1746,14 +1918,14 @@ describe("Sandbox", function () { assert.equals(object.foo, "bar"); }); - it("allows stubbing setters", function () { + it("allows stubbing setters", function() { var object = { foo: undefined, prop: "bar" }; var sandbox = new Sandbox(); - sandbox.stub(object, "foo").set(function (val) { + sandbox.stub(object, "foo").set(function(val) { object.prop = val + "bla"; }); @@ -1762,7 +1934,7 @@ describe("Sandbox", function () { assert.equals(object.prop, "blabla"); }); - it("allows restoring setters", function () { + it("allows restoring setters", function() { var object = { prop: "bar" }; diff --git a/test/sinon-test.js b/test/sinon-test.js index 9e8efc1e1..48d55ef8a 100644 --- a/test/sinon-test.js +++ b/test/sinon-test.js @@ -10,19 +10,18 @@ if (!hasPromise) { var proxyquire = require("proxyquire"); -describe("sinon module", function () { - var sinon, - fakeNise; +describe("sinon module", function() { + var sinon, fakeNise; - beforeEach(function () { + beforeEach(function() { fakeNise = { fakeServer: { - create: function () { + create: function() { return "47c86a4c-6b48-4748-bb8c-d853f999720c"; } }, fakeServerWithClock: { - create: function () { + create: function() { return "e69974f8-4568-48d1-a5e9-2b511a59c14b"; } }, @@ -37,15 +36,16 @@ describe("sinon module", function () { }); }); - describe("deprecated methods", function () { - it(".sandbox.create", function () { + describe("deprecated methods", function() { + it(".sandbox.create", function() { // use full sinon for this test as it compares sinon instance // proxyquire changes the instance, so `actual instanceof Sandbox` returns `false` // see https://github.com/sinonjs/sinon/pull/1586#issuecomment-354457231 sinon = require("../lib/sinon"); // eslint-disable-next-line max-len - var expectedMessage = "`sandbox.create()` is deprecated. Use default sandbox at `sinon.sandbox` or create new sandboxes with `sinon.createSandbox()`"; + var expectedMessage = + "`sandbox.create()` is deprecated. Use default sandbox at `sinon.sandbox` or create new sandboxes with `sinon.createSandbox()`"; var infoStub = sinon.stub(console, "info"); var actual = sinon.sandbox.create(); @@ -57,9 +57,9 @@ describe("sinon module", function () { }); }); - describe("exports", function () { - describe("default sandbox", function () { - it("should be an instance of Sandbox", function () { + describe("exports", function() { + describe("default sandbox", function() { + it("should be an instance of Sandbox", function() { // use full sinon for this test as it compares sinon instance // proxyquire changes the instance, so `actual instanceof Sandbox` returns `false` // see https://github.com/sinonjs/sinon/pull/1586#issuecomment-354457231 @@ -69,54 +69,54 @@ describe("sinon module", function () { }); }); - describe("createSandbox", function () { - it("should be a unary Function named 'createSandbox'", function () { + describe("createSandbox", function() { + it("should be a unary Function named 'createSandbox'", function() { assert.isFunction(sinon.createSandbox); assert.equals(sinon.createSandbox.length, 1); assert.equals(sinon.createSandbox.name, "createSandbox"); }); }); - describe("fakeServer", function () { - it("should be the fakeServer export from nise", function () { + describe("fakeServer", function() { + it("should be the fakeServer export from nise", function() { assert.same(sinon.fakeServer, fakeNise.fakeServer); }); }); - describe("createFakeServer", function () { - it("should be fakeServer.create from nise", function () { + describe("createFakeServer", function() { + it("should be fakeServer.create from nise", function() { assert.equals(sinon.createFakeServer(), fakeNise.fakeServer.create()); }); }); - describe("fakeServerWithClock", function () { - it("should be the fakeServerWithClock export from nise", function () { + describe("fakeServerWithClock", function() { + it("should be the fakeServerWithClock export from nise", function() { assert.same(sinon.fakeServerWithClock, fakeNise.fakeServerWithClock); }); }); - describe("createFakeServerWithClock", function () { - it("should be fakeServerWithClock.create from nise", function () { + describe("createFakeServerWithClock", function() { + it("should be fakeServerWithClock.create from nise", function() { assert.equals(sinon.createFakeServerWithClock(), fakeNise.fakeServerWithClock.create()); }); }); - describe("xhr", function () { - it("should be the fakeXhr.xhr export from nise", function () { + describe("xhr", function() { + it("should be the fakeXhr.xhr export from nise", function() { assert.equals(sinon.xhr, fakeNise.fakeXhr.xhr); }); }); - describe("FakeXMLHttpRequest", function () { - it("should be the fakeXhr.FakeXMLHttpRequest export from nise", function () { + describe("FakeXMLHttpRequest", function() { + it("should be the fakeXhr.FakeXMLHttpRequest export from nise", function() { assert.equals(sinon.FakeXMLHttpRequest, fakeNise.fakeXhr.FakeXMLHttpRequest); }); }); - describe("useFakeXMLHttpRequest", function () { + describe("useFakeXMLHttpRequest", function() { var nise; - beforeEach(function () { + beforeEach(function() { // use full sinon for this test as it compares sinon instance // proxyquire changes the instance, so `actual instanceof Sandbox` returns `false` // see https://github.com/sinonjs/sinon/pull/1586#issuecomment-354457231 @@ -125,11 +125,11 @@ describe("sinon module", function () { nise = require("nise"); }); - afterEach(function () { + afterEach(function() { nise.fakeXhr.useFakeXMLHttpRequest.restore(); }); - it("should be the fakeXhr.useFakeXMLHttpRequest export from nise", function () { + it("should be the fakeXhr.useFakeXMLHttpRequest export from nise", function() { sinon.spy(nise.fakeXhr, "useFakeXMLHttpRequest"); sinon.useFakeXMLHttpRequest(); assert.isTrue(nise.fakeXhr.useFakeXMLHttpRequest.called); diff --git a/test/spy-test.js b/test/spy-test.js index 47ed12f3f..0c13be492 100644 --- a/test/spy-test.js +++ b/test/spy-test.js @@ -7,23 +7,23 @@ var assert = referee.assert; var refute = referee.refute; function spyCalledTests(method) { - return function () { + return function() { // eslint-disable-next-line mocha/no-top-level-hooks - beforeEach(function () { + beforeEach(function() { this.spy = createSpy.create(); }); - it("returns false if spy was not called", function () { + it("returns false if spy was not called", function() { assert.isFalse(this.spy[method](1, 2, 3)); }); - it("returns true if spy was called with args", function () { + it("returns true if spy was called with args", function() { this.spy(1, 2, 3); assert(this.spy[method](1, 2, 3)); }); - it("returns true if called with args at least once", function () { + it("returns true if called with args at least once", function() { this.spy(1, 3, 3); this.spy(1, 2, 3); this.spy(3, 2, 3); @@ -31,7 +31,7 @@ function spyCalledTests(method) { assert(this.spy[method](1, 2, 3)); }); - it("returns false if not called with args", function () { + it("returns false if not called with args", function() { this.spy(1, 3, 3); this.spy(2); this.spy(); @@ -39,13 +39,13 @@ function spyCalledTests(method) { assert.isFalse(this.spy[method](1, 2, 3)); }); - it("returns false if not called with undefined", function () { + it("returns false if not called with undefined", function() { this.spy(); assert.isFalse(this.spy[method](undefined)); }); - it("returns true for partial match", function () { + it("returns true for partial match", function() { this.spy(1, 3, 3); this.spy(2); this.spy(); @@ -53,19 +53,19 @@ function spyCalledTests(method) { assert(this.spy[method](1, 3)); }); - it("matchs all arguments individually, not as array", function () { + it("matchs all arguments individually, not as array", function() { this.spy([1, 2, 3]); assert.isFalse(this.spy[method](1, 2, 3)); }); - it("uses matcher", function () { + it("uses matcher", function() { this.spy("abc"); assert(this.spy[method](sinonMatch.typeOf("string"))); }); - it("uses matcher in object", function () { + it("uses matcher in object", function() { this.spy({ some: "abc" }); assert(this.spy[method]({ some: sinonMatch.typeOf("string") })); @@ -74,8 +74,8 @@ function spyCalledTests(method) { // https://github.com/sinonjs/sinon/issues/1245 // Using the `calledWithMatch` should work with objects that don't have // a hasOwnProperty function. - describe("when called with an Object without a prototype", function () { - it("must not throw", function () { + describe("when called with an Object without a prototype", function() { + it("must not throw", function() { var spy = this.spy; var objectWithoutPrototype = Object.create(null); @@ -86,7 +86,7 @@ function spyCalledTests(method) { objectWithoutPrototype: objectWithoutPrototype }); - refute.exception(function () { + refute.exception(function() { spy.calledWithMatch({ objectWithoutPrototype: objectWithoutPrototype }); @@ -97,25 +97,25 @@ function spyCalledTests(method) { } function spyAlwaysCalledTests(method) { - return function () { + return function() { // eslint-disable-next-line mocha/no-top-level-hooks, mocha/no-sibling-hooks - beforeEach(function () { + beforeEach(function() { this.spy = createSpy.create(); }); // eslint-disable-next-line mocha/no-identical-title - it("returns false if spy was not called", function () { + it("returns false if spy was not called", function() { assert.isFalse(this.spy[method](1, 2, 3)); }); // eslint-disable-next-line mocha/no-identical-title - it("returns true if spy was called with args", function () { + it("returns true if spy was called with args", function() { this.spy(1, 2, 3); assert(this.spy[method](1, 2, 3)); }); - it("returns false if called with args only once", function () { + it("returns false if called with args only once", function() { this.spy(1, 3, 3); this.spy(1, 2, 3); this.spy(3, 2, 3); @@ -124,7 +124,7 @@ function spyAlwaysCalledTests(method) { }); // eslint-disable-next-line mocha/no-identical-title - it("returns false if not called with args", function () { + it("returns false if not called with args", function() { this.spy(1, 3, 3); this.spy(2); this.spy(); @@ -133,13 +133,13 @@ function spyAlwaysCalledTests(method) { }); // eslint-disable-next-line mocha/no-identical-title - it("returns true for partial match", function () { + it("returns true for partial match", function() { this.spy(1, 3, 3); assert(this.spy[method](1, 3)); }); - it("returns true for partial match on many calls", function () { + it("returns true for partial match on many calls", function() { this.spy(1, 3, 3); this.spy(1, 3); this.spy(1, 3, 4, 5); @@ -149,7 +149,7 @@ function spyAlwaysCalledTests(method) { }); // eslint-disable-next-line mocha/no-identical-title - it("matchs all arguments individually, not as array", function () { + it("matchs all arguments individually, not as array", function() { this.spy([1, 2, 3]); assert.isFalse(this.spy[method](1, 2, 3)); @@ -158,23 +158,23 @@ function spyAlwaysCalledTests(method) { } function spyNeverCalledTests(method) { - return function () { + return function() { // eslint-disable-next-line mocha/no-top-level-hooks, mocha/no-sibling-hooks - beforeEach(function () { + beforeEach(function() { this.spy = createSpy.create(); }); - it("returns true if spy was not called", function () { + it("returns true if spy was not called", function() { assert(this.spy[method](1, 2, 3)); }); - it("returns false if spy was called with args", function () { + it("returns false if spy was called with args", function() { this.spy(1, 2, 3); assert.isFalse(this.spy[method](1, 2, 3)); }); - it("returns false if called with args at least once", function () { + it("returns false if called with args at least once", function() { this.spy(1, 3, 3); this.spy(1, 2, 3); this.spy(3, 2, 3); @@ -182,7 +182,7 @@ function spyNeverCalledTests(method) { assert.isFalse(this.spy[method](1, 2, 3)); }); - it("returns true if not called with args", function () { + it("returns true if not called with args", function() { this.spy(1, 3, 3); this.spy(2); this.spy(); @@ -190,7 +190,7 @@ function spyNeverCalledTests(method) { assert(this.spy[method](1, 2, 3)); }); - it("returns false for partial match", function () { + it("returns false for partial match", function() { this.spy(1, 3, 3); this.spy(2); this.spy(); @@ -199,7 +199,7 @@ function spyNeverCalledTests(method) { }); // eslint-disable-next-line mocha/no-identical-title - it("matchs all arguments individually, not as array", function () { + it("matchs all arguments individually, not as array", function() { this.spy([1, 2, 3]); assert(this.spy[method](1, 2, 3)); @@ -207,14 +207,14 @@ function spyNeverCalledTests(method) { }; } -describe("spy", function () { - it("does not throw if called without function", function () { - refute.exception(function () { +describe("spy", function() { + it("does not throw if called without function", function() { + refute.exception(function() { createSpy.create(); }); }); - it("does not throw when calling anonymous spy", function () { + it("does not throw when calling anonymous spy", function() { var spy = createSpy.create(); refute.exception(spy); @@ -222,37 +222,43 @@ describe("spy", function () { assert(spy.called); }); - it("returns spy function", function () { - var func = function () { return; }; + it("returns spy function", function() { + var func = function() { + return; + }; var spy = createSpy.create(func); assert.isFunction(spy); refute.same(func, spy); }); - it("mirrors custom properties on function", function () { - var func = function () { return; }; + it("mirrors custom properties on function", function() { + var func = function() { + return; + }; func.myProp = 42; var spy = createSpy.create(func); assert.equals(spy.myProp, func.myProp); }); - it("does not define create method", function () { + it("does not define create method", function() { var spy = createSpy.create(); refute.defined(spy.create); }); - it("does not overwrite original create property", function () { - var func = function () { return; }; - var object = func.create = {}; + it("does not overwrite original create property", function() { + var func = function() { + return; + }; + var object = (func.create = {}); var spy = createSpy.create(func); assert.same(spy.create, object); }); - it("sets up logging arrays", function () { + it("sets up logging arrays", function() { var spy = createSpy.create(); assert.isArray(spy.args); @@ -261,7 +267,7 @@ describe("spy", function () { assert.isArray(spy.exceptions); }); - it("works with getters", function () { + it("works with getters", function() { var object = { get property() { return 42; @@ -273,7 +279,7 @@ describe("spy", function () { assert(spy.get.calledOnce); }); - it("works with setters", function () { + it("works with setters", function() { var object = { get test() { return this.property; @@ -292,7 +298,7 @@ describe("spy", function () { assert.equals(object.property, 84); }); - it("works with setters and getters combined", function () { + it("works with setters and getters combined", function() { var object = { get test() { return this.property; @@ -310,23 +316,23 @@ describe("spy", function () { assert(spy.get.calledOnce); }); - describe("global.Error", function () { - beforeEach(function () { + describe("global.Error", function() { + beforeEach(function() { this.originalError = global.Error; }); - afterEach(function () { + afterEach(function() { global.Error = this.originalError; }); - it("creates a spy for Error", function () { - refute.exception(function () { + it("creates a spy for Error", function() { + refute.exception(function() { createSpy(global, "Error"); }); }); }); - it("should work with combination of withArgs arguments and order of calling withArgs", function () { + it("should work with combination of withArgs arguments and order of calling withArgs", function() { function assertSpy(spy) { // assert callCount assert.equals(spy.callCount, 4); @@ -344,19 +350,14 @@ describe("spy", function () { assert.equals(spy.getCall(3).args[0], 1); assert.equals(spy.getCall(3).args[1], 2); refute.defined(spy.getCall(3).args[2]); - ["args", "callCount", "callId"].forEach(function (propName) { - assert.equals(spy.withArgs(1).getCall(0)[propName], - spy.getCall(1)[propName]); - assert.equals(spy.withArgs(1).getCall(1)[propName], - spy.getCall(2)[propName]); - assert.equals(spy.withArgs(1).getCall(2)[propName], - spy.getCall(3)[propName]); + ["args", "callCount", "callId"].forEach(function(propName) { + assert.equals(spy.withArgs(1).getCall(0)[propName], spy.getCall(1)[propName]); + assert.equals(spy.withArgs(1).getCall(1)[propName], spy.getCall(2)[propName]); + assert.equals(spy.withArgs(1).getCall(2)[propName], spy.getCall(3)[propName]); assert.isNull(spy.withArgs(1).getCall(3)); - assert.equals(spy.withArgs(1, 1).getCall(0)[propName], - spy.getCall(2)[propName]); + assert.equals(spy.withArgs(1, 1).getCall(0)[propName], spy.getCall(2)[propName]); assert.isNull(spy.withArgs(1, 1).getCall(1)); - assert.equals(spy.withArgs(1, 2).getCall(0)[propName], - spy.getCall(3)[propName]); + assert.equals(spy.withArgs(1, 2).getCall(0)[propName], spy.getCall(3)[propName]); assert.isNull(spy.withArgs(1, 2).getCall(1)); }); @@ -380,8 +381,12 @@ describe("spy", function () { } var object = { - f1: function () { return; }, - f2: function () { return; } + f1: function() { + return; + }, + f2: function() { + return; + } }; // f1: the order of withArgs(1), withArgs(1, 1) @@ -417,8 +422,8 @@ describe("spy", function () { assertSpy(spy2); }); - describe(".named", function () { - it("sets displayName", function () { + describe(".named", function() { + it("sets displayName", function() { var spy = createSpy(); var retval = spy.named("beep"); assert.equals(spy.displayName, "beep"); @@ -426,11 +431,11 @@ describe("spy", function () { }); }); - describe("call", function () { - it("calls underlying function", function () { + describe("call", function() { + it("calls underlying function", function() { var called = false; - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { called = true; }); @@ -439,8 +444,10 @@ describe("spy", function () { assert(called); }); - it("passes 'new' to underlying function", function () { - function TestClass() { return; } + it("passes 'new' to underlying function", function() { + function TestClass() { + return; + } var SpyClass = createSpy.create(TestClass); @@ -449,10 +456,10 @@ describe("spy", function () { assert(instance instanceof TestClass); }); - it("passs arguments to function", function () { + it("passs arguments to function", function() { var actualArgs; - var func = function (a, b, c, d) { + var func = function(a, b, c, d) { actualArgs = [a, b, c, d]; }; @@ -463,10 +470,10 @@ describe("spy", function () { assert.equals(actualArgs, args); }); - it("maintains this binding", function () { + it("maintains this binding", function() { var actualThis; - var func = function () { + var func = function() { actualThis = this; }; @@ -477,10 +484,10 @@ describe("spy", function () { assert.same(actualThis, object); }); - it("returns function's return value", function () { + it("returns function's return value", function() { var object = {}; - var func = function () { + var func = function() { return object; }; @@ -490,47 +497,62 @@ describe("spy", function () { assert.same(actualReturn, object); }); - it("throws if function throws", function () { + it("throws if function throws", function() { var err = new Error(); - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { throw err; }); assert.exception(spy, err); }); - it("retains function length 0", function () { - var spy = createSpy.create(function () { return; }); + it("retains function length 0", function() { + var spy = createSpy.create(function() { + return; + }); assert.equals(spy.length, 0); }); - it("retains function length 1", function () { - var spy = createSpy.create(function (a) { return; }); // eslint-disable-line no-unused-vars + it("retains function length 1", function() { + // eslint-disable-next-line no-unused-vars + var spy = createSpy.create(function(a) { + return; + }); assert.equals(spy.length, 1); }); - it("retains function length 2", function () { - var spy = createSpy.create(function (a, b) { return; }); // eslint-disable-line no-unused-vars + it("retains function length 2", function() { + // eslint-disable-next-line no-unused-vars + var spy = createSpy.create(function(a, b) { + return; + }); assert.equals(spy.length, 2); }); - it("retains function length 3", function () { - var spy = createSpy.create(function (a, b, c) { return; }); // eslint-disable-line no-unused-vars + it("retains function length 3", function() { + // eslint-disable-next-line no-unused-vars + var spy = createSpy.create(function(a, b, c) { + return; + }); assert.equals(spy.length, 3); }); - it("retains function length 4", function () { - var spy = createSpy.create(function (a, b, c, d) { return; }); // eslint-disable-line no-unused-vars + it("retains function length 4", function() { + // eslint-disable-next-line no-unused-vars + var spy = createSpy.create(function(a, b, c, d) { + return; + }); assert.equals(spy.length, 4); }); - it("retains function length 12", function () { - var func12Args = function (a, b, c, d, e, f, g, h, i, j, k, l) { // eslint-disable-line no-unused-vars + it("retains function length 12", function() { + // eslint-disable-next-line no-unused-vars + var func12Args = function(a, b, c, d, e, f, g, h, i, j, k, l) { return; }; var spy = createSpy.create(func12Args); @@ -539,22 +561,22 @@ describe("spy", function () { }); }); - describe(".called", function () { - beforeEach(function () { + describe(".called", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false prior to calling the spy", function () { + it("is false prior to calling the spy", function() { assert.isFalse(this.spy.called); }); - it("is true after calling the spy once", function () { + it("is true after calling the spy once", function() { this.spy(); assert(this.spy.called); }); - it("is true after calling the spy twice", function () { + it("is true after calling the spy twice", function() { this.spy(); this.spy(); @@ -562,38 +584,38 @@ describe("spy", function () { }); }); - describe(".notCalled", function () { - beforeEach(function () { + describe(".notCalled", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is true prior to calling the spy", function () { + it("is true prior to calling the spy", function() { assert.isTrue(this.spy.notCalled); }); - it("is false after calling the spy once", function () { + it("is false after calling the spy once", function() { this.spy(); assert.isFalse(this.spy.notCalled); }); }); - describe(".calledOnce", function () { - beforeEach(function () { + describe(".calledOnce", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false prior to calling the spy", function () { + it("is false prior to calling the spy", function() { assert.isFalse(this.spy.calledOnce); }); - it("is true after calling the spy once", function () { + it("is true after calling the spy once", function() { this.spy(); assert(this.spy.calledOnce); }); - it("is false after calling the spy twice", function () { + it("is false after calling the spy twice", function() { this.spy(); this.spy(); @@ -601,29 +623,29 @@ describe("spy", function () { }); }); - describe(".calledTwice", function () { - beforeEach(function () { + describe(".calledTwice", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false prior to calling the spy", function () { + it("is false prior to calling the spy", function() { assert.isFalse(this.spy.calledTwice); }); - it("is false after calling the spy once", function () { + it("is false after calling the spy once", function() { this.spy(); assert.isFalse(this.spy.calledTwice); }); - it("is true after calling the spy twice", function () { + it("is true after calling the spy twice", function() { this.spy(); this.spy(); assert(this.spy.calledTwice); }); - it("is false after calling the spy thrice", function () { + it("is false after calling the spy thrice", function() { this.spy(); this.spy(); this.spy(); @@ -632,23 +654,23 @@ describe("spy", function () { }); }); - describe(".calledThrice", function () { - beforeEach(function () { + describe(".calledThrice", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false prior to calling the spy", function () { + it("is false prior to calling the spy", function() { assert.isFalse(this.spy.calledThrice); }); - it("is false after calling the spy twice", function () { + it("is false after calling the spy twice", function() { this.spy(); this.spy(); assert.isFalse(this.spy.calledThrice); }); - it("is true after calling the spy thrice", function () { + it("is true after calling the spy thrice", function() { this.spy(); this.spy(); this.spy(); @@ -656,7 +678,7 @@ describe("spy", function () { assert(this.spy.calledThrice); }); - it("is false after calling the spy four times", function () { + it("is false after calling the spy four times", function() { this.spy(); this.spy(); this.spy(); @@ -666,29 +688,29 @@ describe("spy", function () { }); }); - describe(".callCount", function () { - beforeEach(function () { + describe(".callCount", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("reports 0 calls", function () { + it("reports 0 calls", function() { assert.equals(this.spy.callCount, 0); }); - it("records one call", function () { + it("records one call", function() { this.spy(); assert.equals(this.spy.callCount, 1); }); - it("records two calls", function () { + it("records two calls", function() { this.spy(); this.spy(); assert.equals(this.spy.callCount, 2); }); - it("increases call count for each call", function () { + it("increases call count for each call", function() { this.spy(); this.spy(); assert.equals(this.spy.callCount, 2); @@ -698,16 +720,16 @@ describe("spy", function () { }); }); - describe(".calledOn", function () { - beforeEach(function () { + describe(".calledOn", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false if spy wasn't called", function () { + it("is false if spy wasn't called", function() { assert.isFalse(this.spy.calledOn({})); }); - it("is true if called with thisValue", function () { + it("is true if called with thisValue", function() { var object = {}; this.spy.call(object); @@ -715,8 +737,8 @@ describe("spy", function () { }); if (typeof window !== "undefined") { - describe("in browser", function () { - it("is true if called on object at least once", function () { + describe("in browser", function() { + it("is true if called on object at least once", function() { var object = {}; this.spy(); this.spy.call({}); @@ -728,7 +750,7 @@ describe("spy", function () { }); } - it("returns false if not called on object", function () { + it("returns false if not called on object", function() { var object = {}; this.spy.call(object); this.spy(); @@ -736,8 +758,8 @@ describe("spy", function () { assert.isFalse(this.spy.calledOn({})); }); - it("is true if called with matcher that returns true", function () { - var matcher = sinonMatch(function () { + it("is true if called with matcher that returns true", function() { + var matcher = sinonMatch(function() { return true; }); this.spy(); @@ -745,8 +767,8 @@ describe("spy", function () { assert(this.spy.calledOn(matcher)); }); - it("is false if called with matcher that returns false", function () { - var matcher = sinonMatch(function () { + it("is false if called with matcher that returns false", function() { + var matcher = sinonMatch(function() { return false; }); this.spy(); @@ -754,36 +776,38 @@ describe("spy", function () { assert.isFalse(this.spy.calledOn(matcher)); }); - it("invokes matcher.test with given object", function () { + it("invokes matcher.test with given object", function() { var expected = {}; var actual; this.spy.call(expected); - this.spy.calledOn(sinonMatch(function (value) { - actual = value; - })); + this.spy.calledOn( + sinonMatch(function(value) { + actual = value; + }) + ); assert.same(actual, expected); }); }); - describe(".alwaysCalledOn", function () { - beforeEach(function () { + describe(".alwaysCalledOn", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false prior to calling the spy", function () { + it("is false prior to calling the spy", function() { assert.isFalse(this.spy.alwaysCalledOn({})); }); - it("is true if called with thisValue once", function () { + it("is true if called with thisValue once", function() { var object = {}; this.spy.call(object); assert(this.spy.alwaysCalledOn(object)); }); - it("is true if called with thisValue many times", function () { + it("is true if called with thisValue many times", function() { var object = {}; this.spy.call(object); this.spy.call(object); @@ -793,7 +817,7 @@ describe("spy", function () { assert(this.spy.alwaysCalledOn(object)); }); - it("is false if called with another object atleast once", function () { + it("is false if called with another object atleast once", function() { var object = {}; this.spy.call(object); this.spy.call(object); @@ -804,7 +828,7 @@ describe("spy", function () { assert.isFalse(this.spy.alwaysCalledOn(object)); }); - it("is false if never called with expected object", function () { + it("is false if never called with expected object", function() { var object = {}; this.spy(); this.spy(); @@ -814,23 +838,25 @@ describe("spy", function () { }); }); - describe(".calledWithNew", function () { - beforeEach(function () { + describe(".calledWithNew", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false if spy wasn't called", function () { + it("is false if spy wasn't called", function() { assert.isFalse(this.spy.calledWithNew()); }); - it("is true if called with new", function () { + it("is true if called with new", function() { var result = new this.spy(); // eslint-disable-line no-unused-vars, new-cap assert(this.spy.calledWithNew()); }); - it("is true if called with new on custom constructor", function () { - function MyThing() { return; } + it("is true if called with new on custom constructor", function() { + function MyThing() { + return; + } MyThing.prototype = {}; var ns = { MyThing: MyThing }; createSpy(ns, "MyThing"); @@ -839,15 +865,15 @@ describe("spy", function () { assert(ns.MyThing.calledWithNew()); }); - it("is false if called as function", function () { + it("is false if called as function", function() { this.spy(); assert.isFalse(this.spy.calledWithNew()); }); if (typeof window !== "undefined") { - describe("in browser", function () { - it("is true if called with new at least once", function () { + describe("in browser", function() { + it("is true if called with new at least once", function() { var object = {}; this.spy(); var a = new this.spy(); // eslint-disable-line no-unused-vars, new-cap @@ -859,7 +885,7 @@ describe("spy", function () { }); } - it("is true newed constructor returns object", function () { + it("is true newed constructor returns object", function() { function MyThing() { return {}; } @@ -871,17 +897,19 @@ describe("spy", function () { assert(object.MyThing.calledWithNew()); }); - var applyableNatives = (function () { - try { // eslint-disable-line no-restricted-syntax - console.log.apply({}, []); // eslint-disable-line no-console + var applyableNatives = (function() { + // eslint-disable-next-line no-restricted-syntax + try { + // eslint-disable-next-line no-console + console.log.apply({}, []); return true; } catch (e) { return false; } - }()); + })(); if (applyableNatives) { - describe("spied native function", function () { - it("is false when called on spied native function", function () { + describe("spied native function", function() { + it("is false when called on spied native function", function() { var log = { info: console.log }; // eslint-disable-line no-console createSpy(log, "info"); @@ -894,16 +922,16 @@ describe("spy", function () { } }); - describe(".alwaysCalledWithNew", function () { - beforeEach(function () { + describe(".alwaysCalledWithNew", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("is false if spy wasn't called", function () { + it("is false if spy wasn't called", function() { assert.isFalse(this.spy.alwaysCalledWithNew()); }); - it("is true if always called with new", function () { + it("is true if always called with new", function() { /*eslint-disable no-unused-vars, new-cap*/ var result = new this.spy(); var result2 = new this.spy(); @@ -913,7 +941,7 @@ describe("spy", function () { assert(this.spy.alwaysCalledWithNew()); }); - it("is false if called as function once", function () { + it("is false if called as function once", function() { /*eslint-disable no-unused-vars, new-cap*/ var result = new this.spy(); var result2 = new this.spy(); @@ -924,20 +952,22 @@ describe("spy", function () { }); }); - describe(".thisValues", function () { - beforeEach(function () { + describe(".thisValues", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("contains one object", function () { + it("contains one object", function() { var object = {}; this.spy.call(object); assert.equals(this.spy.thisValues, [object]); }); - it("stacks up objects", function () { - function MyConstructor() { return; } + it("stacks up objects", function() { + function MyConstructor() { + return; + } var objects = [{}, [], new MyConstructor(), { id: 243 }]; this.spy(); this.spy.call(objects[0]); @@ -952,26 +982,26 @@ describe("spy", function () { describe(".calledWith", spyCalledTests("calledWith")); describe(".calledWithMatch", spyCalledTests("calledWithMatch")); - describe(".calledWithMatchSpecial", function () { - beforeEach(function () { + describe(".calledWithMatchSpecial", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("checks substring match", function () { + it("checks substring match", function() { this.spy("I like it"); assert(this.spy.calledWithMatch("like")); assert.isFalse(this.spy.calledWithMatch("nope")); }); - it("checks for regexp match", function () { + it("checks for regexp match", function() { this.spy("I like it"); assert(this.spy.calledWithMatch(/[a-z ]+/i)); assert.isFalse(this.spy.calledWithMatch(/[0-9]+/)); }); - it("checks for partial object match", function () { + it("checks for partial object match", function() { this.spy({ foo: "foo", bar: "bar" }); assert(this.spy.calledWithMatch({ bar: "bar" })); @@ -982,26 +1012,26 @@ describe("spy", function () { describe(".alwaysCalledWith", spyAlwaysCalledTests("alwaysCalledWith")); describe(".alwaysCalledWithMatch", spyAlwaysCalledTests("alwaysCalledWithMatch")); - describe(".alwaysCalledWithMatchSpecial", function () { - beforeEach(function () { + describe(".alwaysCalledWithMatchSpecial", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("checks true", function () { + it("checks true", function() { this.spy(true); assert(this.spy.alwaysCalledWithMatch(true)); assert.isFalse(this.spy.alwaysCalledWithMatch(false)); }); - it("checks false", function () { + it("checks false", function() { this.spy(false); assert(this.spy.alwaysCalledWithMatch(false)); assert.isFalse(this.spy.alwaysCalledWithMatch(true)); }); - it("checks substring match", function () { + it("checks substring match", function() { this.spy("test case"); this.spy("some test"); this.spy("all tests"); @@ -1010,7 +1040,7 @@ describe("spy", function () { assert.isFalse(this.spy.alwaysCalledWithMatch("case")); }); - it("checks regexp match", function () { + it("checks regexp match", function() { this.spy("1"); this.spy("2"); this.spy("3"); @@ -1019,7 +1049,7 @@ describe("spy", function () { assert.isFalse(this.spy.alwaysCalledWithMatch(/[12]/)); }); - it("checks partial object match", function () { + it("checks partial object match", function() { this.spy({ a: "a", b: "b" }); this.spy({ c: "c", b: "b" }); this.spy({ b: "b", d: "d" }); @@ -1032,12 +1062,12 @@ describe("spy", function () { describe(".neverCalledWith", spyNeverCalledTests("neverCalledWith")); describe(".neverCalledWithMatch", spyNeverCalledTests("neverCalledWithMatch")); - describe(".neverCalledWithMatchSpecial", function () { - beforeEach(function () { + describe(".neverCalledWithMatchSpecial", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("checks substring match", function () { + it("checks substring match", function() { this.spy("a test", "b test"); assert(this.spy.neverCalledWithMatch("a", "a")); @@ -1046,7 +1076,7 @@ describe("spy", function () { assert.isFalse(this.spy.neverCalledWithMatch("a", "b")); }); - it("checks regexp match", function () { + it("checks regexp match", function() { this.spy("a test", "b test"); assert(this.spy.neverCalledWithMatch(/a/, /a/)); @@ -1055,7 +1085,7 @@ describe("spy", function () { assert.isFalse(this.spy.neverCalledWithMatch(/a/, /b/)); }); - it("checks partial object match", function () { + it("checks partial object match", function() { this.spy({ a: "test", b: "test" }); assert(this.spy.neverCalledWithMatch({ a: "nope" })); @@ -1064,73 +1094,69 @@ describe("spy", function () { }); }); - describe(".args", function () { - beforeEach(function () { + describe(".args", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("contains real arrays", function () { + it("contains real arrays", function() { this.spy(); assert.isArray(this.spy.args[0]); }); - it("contains empty array when no arguments", function () { + it("contains empty array when no arguments", function() { this.spy(); assert.equals(this.spy.args, [[]]); }); - it("contains array with first call's arguments", function () { + it("contains array with first call's arguments", function() { this.spy(1, 2, 3); assert.equals(this.spy.args, [[1, 2, 3]]); }); - it("stacks up arguments in nested array", function () { + it("stacks up arguments in nested array", function() { var objects = [{}, [], { id: 324 }]; this.spy(1, objects[0], 3); this.spy(1, 2, objects[1]); this.spy(objects[2], 2, 3); - assert.equals(this.spy.args, [ - [1, objects[0], 3], - [1, 2, objects[1]], - [objects[2], 2, 3] - ]); + assert.equals(this.spy.args, [[1, objects[0], 3], [1, 2, objects[1]], [objects[2], 2, 3]]); }); }); - describe(".calledWithExactly", function () { - beforeEach(function () { + describe(".calledWithExactly", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("returns false for partial match", function () { + it("returns false for partial match", function() { this.spy(1, 2, 3); assert.isFalse(this.spy.calledWithExactly(1, 2)); }); - it("returns false for missing arguments", function () { + it("returns false for missing arguments", function() { this.spy(1, 2, 3); assert.isFalse(this.spy.calledWithExactly(1, 2, 3, 4)); }); - it("returns true for exact match", function () { + it("returns true for exact match", function() { this.spy(1, 2, 3); assert(this.spy.calledWithExactly(1, 2, 3)); }); - it("matchs by strict comparison", function () { + it("matchs by strict comparison", function() { this.spy({}, []); assert.isFalse(this.spy.calledWithExactly({}, [], null)); }); - it("returns true for one exact match", function () { + it("returns true for one exact match", function() { var object = {}; var array = []; this.spy({}, []); @@ -1140,74 +1166,74 @@ describe("spy", function () { assert(this.spy.calledWithExactly(object, array)); }); - it("returns true when all properties of an object argument match", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns true when all properties of an object argument match", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert(this.spy.calledWithExactly({a: 1, b: 2, c: 3})); + assert(this.spy.calledWithExactly({ a: 1, b: 2, c: 3 })); }); - it("returns false when a property of an object argument is set to undefined", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns false when a property of an object argument is set to undefined", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert.isFalse(this.spy.calledWithExactly({a: 1, b: 2, c: undefined})); + assert.isFalse(this.spy.calledWithExactly({ a: 1, b: 2, c: undefined })); }); - it("returns false when a property of an object argument is set to a different value", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns false when a property of an object argument is set to a different value", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert.isFalse(this.spy.calledWithExactly({a: 1, b: 2, c: "blah"})); + assert.isFalse(this.spy.calledWithExactly({ a: 1, b: 2, c: "blah" })); }); - it("returns false when an object argument has a different property/value pair", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns false when an object argument has a different property/value pair", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert.isFalse(this.spy.calledWithExactly({a: 1, b: 2, foo: "blah"})); + assert.isFalse(this.spy.calledWithExactly({ a: 1, b: 2, foo: "blah" })); }); - it("returns false when property of Object argument is set to undefined and has a different name", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns false when property of Object argument is set to undefined and has a different name", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert.isFalse(this.spy.calledWithExactly({a: 1, b: 2, foo: undefined})); + assert.isFalse(this.spy.calledWithExactly({ a: 1, b: 2, foo: undefined })); }); - it("returns false when any properties of an object argument aren't present", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns false when any properties of an object argument aren't present", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert.isFalse(this.spy.calledWithExactly({a: 1, b: 2})); + assert.isFalse(this.spy.calledWithExactly({ a: 1, b: 2 })); }); - it("returns false when an object argument has extra properties", function () { - this.spy({a: 1, b: 2, c: 3}); + it("returns false when an object argument has extra properties", function() { + this.spy({ a: 1, b: 2, c: 3 }); - assert.isFalse(this.spy.calledWithExactly({a: 1, b: 2, c: 3, d: 4})); + assert.isFalse(this.spy.calledWithExactly({ a: 1, b: 2, c: 3, d: 4 })); }); }); - describe(".calledOnceWith", function () { - beforeEach(function () { + describe(".calledOnceWith", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("returns true for not exact match", function () { + it("returns true for not exact match", function() { this.spy(1, 2, 3, 4); assert.isTrue(this.spy.calledOnceWith(1, 2, 3)); }); - it("returns false for matching calls but called more then once", function () { + it("returns false for matching calls but called more then once", function() { this.spy(1, 2, 3, 4); this.spy(1, 2, 3, 6); assert.isFalse(this.spy.calledOnceWith(1, 2, 3)); }); - it("return false for one mismatched call", function () { + it("return false for one mismatched call", function() { this.spy(1, 2); assert.isFalse(this.spy.calledOnceWith(1, 2, 3)); }); - it("return false for one mismatched call with some other ", function () { + it("return false for one mismatched call with some other ", function() { this.spy(1, 2, 3); this.spy(1, 2); @@ -1215,31 +1241,31 @@ describe("spy", function () { }); }); - describe(".calledOnceWithExactly", function () { - beforeEach(function () { + describe(".calledOnceWithExactly", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("returns true for exact match", function () { + it("returns true for exact match", function() { this.spy(1, 2, 3); assert.isTrue(this.spy.calledOnceWithExactly(1, 2, 3)); }); - it("returns false for exact parameters but called more then once", function () { + it("returns false for exact parameters but called more then once", function() { this.spy(1, 2, 3); this.spy(1, 2, 3); assert.isFalse(this.spy.calledOnceWithExactly(1, 2, 3)); }); - it("return false for one mismatched call", function () { + it("return false for one mismatched call", function() { this.spy(1, 2); assert.isFalse(this.spy.calledOnceWithExactly(1, 2, 3)); }); - it("return false for one mismatched call with some other ", function () { + it("return false for one mismatched call with some other ", function() { this.spy(1, 2, 3); this.spy(1, 2); @@ -1247,36 +1273,36 @@ describe("spy", function () { }); }); - describe(".alwaysCalledWithExactly", function () { - beforeEach(function () { + describe(".alwaysCalledWithExactly", function() { + beforeEach(function() { this.spy = createSpy.create(); }); - it("returns false for partial match", function () { + it("returns false for partial match", function() { this.spy(1, 2, 3); assert.isFalse(this.spy.alwaysCalledWithExactly(1, 2)); }); - it("returns false for missing arguments", function () { + it("returns false for missing arguments", function() { this.spy(1, 2, 3); assert.isFalse(this.spy.alwaysCalledWithExactly(1, 2, 3, 4)); }); - it("returns true for exact match", function () { + it("returns true for exact match", function() { this.spy(1, 2, 3); assert(this.spy.alwaysCalledWithExactly(1, 2, 3)); }); - it("returns false for excess arguments", function () { + it("returns false for excess arguments", function() { this.spy({}, []); assert.isFalse(this.spy.alwaysCalledWithExactly({}, [], null)); }); - it("returns false for one exact match", function () { + it("returns false for one exact match", function() { var object = {}; var array = []; this.spy({}, []); @@ -1286,7 +1312,7 @@ describe("spy", function () { assert(this.spy.alwaysCalledWithExactly(object, array)); }); - it("returns true for only exact matches", function () { + it("returns true for only exact matches", function() { var object = {}; var array = []; @@ -1297,7 +1323,7 @@ describe("spy", function () { assert(this.spy.alwaysCalledWithExactly(object, array)); }); - it("returns false for no exact matches", function () { + it("returns false for no exact matches", function() { var object = {}; var array = []; @@ -1309,24 +1335,24 @@ describe("spy", function () { }); }); - describe(".threw", function () { - beforeEach(function () { + describe(".threw", function() { + beforeEach(function() { this.spy = createSpy.create(); - this.spyWithTypeError = createSpy.create(function () { + this.spyWithTypeError = createSpy.create(function() { throw new TypeError(); }); - this.spyWithStringError = createSpy.create(function () { + this.spyWithStringError = createSpy.create(function() { // eslint-disable-next-line no-throw-literal throw "error"; }); }); - it("returns exception thrown by function", function () { + it("returns exception thrown by function", function() { var err = new Error(); - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { throw err; }); @@ -1335,62 +1361,62 @@ describe("spy", function () { assert(spy.threw(err)); }); - it("returns false if spy did not throw", function () { + it("returns false if spy did not throw", function() { this.spy(); assert.isFalse(this.spy.threw()); }); - it("returns true if spy threw", function () { + it("returns true if spy threw", function() { assert.exception(this.spyWithTypeError); assert(this.spyWithTypeError.threw()); }); - it("returns true if string type matches", function () { + it("returns true if string type matches", function() { assert.exception(this.spyWithTypeError); assert(this.spyWithTypeError.threw("TypeError")); }); - it("returns false if string did not match", function () { + it("returns false if string did not match", function() { assert.exception(this.spyWithTypeError); assert.isFalse(this.spyWithTypeError.threw("Error")); }); - it("returns false if spy did not throw specified error", function () { + it("returns false if spy did not throw specified error", function() { this.spy(); assert.isFalse(this.spy.threw("Error")); }); - it("returns true if string matches", function () { + it("returns true if string matches", function() { assert.exception(this.spyWithStringError); assert(this.spyWithStringError.threw("error")); }); - it("returns false if strings do not match", function () { + it("returns false if strings do not match", function() { assert.exception(this.spyWithStringError); assert.isFalse(this.spyWithStringError.threw("not the error")); }); }); - describe(".alwaysThrew", function () { - beforeEach(function () { + describe(".alwaysThrew", function() { + beforeEach(function() { this.spy = createSpy.create(); - this.spyWithTypeError = createSpy.create(function () { + this.spyWithTypeError = createSpy.create(function() { throw new TypeError(); }); }); - it("returns true when spy threw", function () { + it("returns true when spy threw", function() { var err = new Error(); - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { throw err; }); @@ -1399,40 +1425,40 @@ describe("spy", function () { assert(spy.alwaysThrew(err)); }); - it("returns false if spy did not throw", function () { + it("returns false if spy did not throw", function() { this.spy(); assert.isFalse(this.spy.alwaysThrew()); }); - it("returns true if spy threw", function () { + it("returns true if spy threw", function() { assert.exception(this.spyWithTypeError); assert(this.spyWithTypeError.alwaysThrew()); }); - it("returns true if string type matches", function () { + it("returns true if string type matches", function() { assert.exception(this.spyWithTypeError); assert(this.spyWithTypeError.alwaysThrew("TypeError")); }); - it("returns false if string did not match", function () { + it("returns false if string did not match", function() { assert.exception(this.spyWithTypeError); assert.isFalse(this.spyWithTypeError.alwaysThrew("Error")); }); - it("returns false if spy did not throw specified error", function () { + it("returns false if spy did not throw specified error", function() { this.spy(); assert.isFalse(this.spy.alwaysThrew("Error")); }); - it("returns false if some calls did not throw", function () { + it("returns false if some calls did not throw", function() { var callCount = 0; - this.spy = createSpy(function () { + this.spy = createSpy(function() { callCount += 1; if (callCount === 1) { throw new Error("throwing on first call"); @@ -1446,7 +1472,7 @@ describe("spy", function () { assert.isFalse(this.spy.alwaysThrew()); }); - it("returns true if all calls threw", function () { + it("returns true if all calls threw", function() { assert.exception(this.spyWithTypeError); assert.exception(this.spyWithTypeError); @@ -1454,7 +1480,7 @@ describe("spy", function () { assert(this.spyWithTypeError.alwaysThrew()); }); - it("returns true if all calls threw same type", function () { + it("returns true if all calls threw same type", function() { assert.exception(this.spyWithTypeError); assert.exception(this.spyWithTypeError); @@ -1463,34 +1489,34 @@ describe("spy", function () { }); }); - describe(".exceptions", function () { - beforeEach(function () { + describe(".exceptions", function() { + beforeEach(function() { this.spy = createSpy.create(); - var error = this.error = {}; + var error = (this.error = {}); - this.spyWithTypeError = createSpy.create(function () { + this.spyWithTypeError = createSpy.create(function() { throw error; }); }); - it("contains exception thrown by function", function () { + it("contains exception thrown by function", function() { assert.exception(this.spyWithTypeError); assert.equals(this.spyWithTypeError.exceptions, [this.error]); }); - it("contains undefined entry when function did not throw", function () { + it("contains undefined entry when function did not throw", function() { this.spy(); assert.equals(this.spy.exceptions.length, 1); refute.defined(this.spy.exceptions[0]); }); - it("stacks up exceptions and undefined", function () { + it("stacks up exceptions and undefined", function() { var calls = 0; var err = this.error; - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { calls += 1; if (calls % 2 === 0) { @@ -1517,24 +1543,31 @@ describe("spy", function () { }); }); - describe(".returned", function () { - it("returns true when no argument", function () { + describe(".returned", function() { + it("returns true when no argument", function() { var spy = createSpy.create(); spy(); assert(spy.returned()); }); - it("returns true for undefined when no explicit return", function () { + it("returns true for undefined when no explicit return", function() { var spy = createSpy.create(); spy(); assert(spy.returned(undefined)); }); - it("returns true when returned value once", function () { - var values = [{}, 2, "hey", function () { return; }]; - var spy = createSpy.create(function () { + it("returns true when returned value once", function() { + var values = [ + {}, + 2, + "hey", + function() { + return; + } + ]; + var spy = createSpy.create(function() { return values[spy.callCount]; }); @@ -1546,9 +1579,16 @@ describe("spy", function () { assert(spy.returned(values[3])); }); - it("returns false when value is never returned", function () { - var values = [{}, 2, "hey", function () { return; }]; - var spy = createSpy.create(function () { + it("returns false when value is never returned", function() { + var values = [ + {}, + 2, + "hey", + function() { + return; + } + ]; + var spy = createSpy.create(function() { return values[spy.callCount]; }); @@ -1560,9 +1600,9 @@ describe("spy", function () { assert.isFalse(spy.returned({ id: 42 })); }); - it("returns true when value is returned several times", function () { + it("returns true when value is returned several times", function() { var object = { id: 42 }; - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { return object; }); @@ -1573,9 +1613,9 @@ describe("spy", function () { assert(spy.returned(object)); }); - it("compares values deeply", function () { + it("compares values deeply", function() { var object = { deep: { id: 42 } }; - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { return object; }); @@ -1584,9 +1624,9 @@ describe("spy", function () { assert(spy.returned({ deep: { id: 42 } })); }); - it("compares values strictly using match.same", function () { + it("compares values strictly using match.same", function() { var object = { id: 42 }; - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { return object; }); @@ -1597,8 +1637,8 @@ describe("spy", function () { }); }); - describe(".returnValues", function () { - it("contains undefined when function does not return explicitly", function () { + describe(".returnValues", function() { + it("contains undefined when function does not return explicitly", function() { var spy = createSpy.create(); spy(); @@ -1606,10 +1646,10 @@ describe("spy", function () { refute.defined(spy.returnValues[0]); }); - it("contains return value", function () { + it("contains return value", function() { var object = { id: 42 }; - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { return object; }); @@ -1618,8 +1658,8 @@ describe("spy", function () { assert.equals(spy.returnValues, [object]); }); - it("contains undefined when function throws", function () { - var spy = createSpy.create(function () { + it("contains undefined when function throws", function() { + var spy = createSpy.create(function() { throw new Error(); }); @@ -1629,16 +1669,18 @@ describe("spy", function () { refute.defined(spy.returnValues[0]); }); - it("contains the created object for spied constructors", function () { - var Spy = createSpy.create(function () { return; }); + it("contains the created object for spied constructors", function() { + var Spy = createSpy.create(function() { + return; + }); var result = new Spy(); assert.equals(Spy.returnValues[0], result); }); - it("contains the return value for spied constructors that explicitly return objects", function () { - var Spy = createSpy.create(function () { + it("contains the return value for spied constructors that explicitly return objects", function() { + var Spy = createSpy.create(function() { return { isExplicitlyCreatedValue: true }; }); @@ -1648,8 +1690,8 @@ describe("spy", function () { assert.equals(Spy.returnValues[0], result); }); - it("contains the created object for spied constructors that explicitly return primitive values", function () { - var Spy = createSpy.create(function () { + it("contains the created object for spied constructors that explicitly return primitive values", function() { + var Spy = createSpy.create(function() { return 10; }); @@ -1659,11 +1701,11 @@ describe("spy", function () { assert.equals(Spy.returnValues[0], result); }); - it("stacks up return values", function () { + it("stacks up return values", function() { var calls = 0; /*eslint consistent-return: "off"*/ - var spy = createSpy.create(function () { + var spy = createSpy.create(function() { calls += 1; if (calls % 2 === 0) { @@ -1686,43 +1728,43 @@ describe("spy", function () { }); }); - describe(".calledBefore", function () { - beforeEach(function () { + describe(".calledBefore", function() { + beforeEach(function() { this.spyA = createSpy(); this.spyB = createSpy(); }); - it("is function", function () { + it("is function", function() { assert.isFunction(this.spyA.calledBefore); }); - it("returns true if first call to A was before first to B", function () { + it("returns true if first call to A was before first to B", function() { this.spyA(); this.spyB(); assert(this.spyA.calledBefore(this.spyB)); }); - it("compares call order of calls directly", function () { + it("compares call order of calls directly", function() { this.spyA(); this.spyB(); assert(this.spyA.getCall(0).calledBefore(this.spyB.getCall(0))); }); - it("returns false if not called", function () { + it("returns false if not called", function() { this.spyB(); assert.isFalse(this.spyA.calledBefore(this.spyB)); }); - it("returns true if other not called", function () { + it("returns true if other not called", function() { this.spyA(); assert(this.spyA.calledBefore(this.spyB)); }); - it("returns false if other called first", function () { + it("returns false if other called first", function() { this.spyB(); this.spyA(); this.spyB(); @@ -1731,43 +1773,43 @@ describe("spy", function () { }); }); - describe(".calledAfter", function () { - beforeEach(function () { + describe(".calledAfter", function() { + beforeEach(function() { this.spyA = createSpy(); this.spyB = createSpy(); }); - it("is function", function () { + it("is function", function() { assert.isFunction(this.spyA.calledAfter); }); - it("returns true if first call to A was after first to B", function () { + it("returns true if first call to A was after first to B", function() { this.spyB(); this.spyA(); assert(this.spyA.calledAfter(this.spyB)); }); - it("compares calls directly", function () { + it("compares calls directly", function() { this.spyB(); this.spyA(); assert(this.spyA.getCall(0).calledAfter(this.spyB.getCall(0))); }); - it("returns false if not called", function () { + it("returns false if not called", function() { this.spyB(); assert.isFalse(this.spyA.calledAfter(this.spyB)); }); - it("returns false if other not called", function () { + it("returns false if other not called", function() { this.spyA(); assert.isFalse(this.spyA.calledAfter(this.spyB)); }); - it("returns true if called anytime after other", function () { + it("returns true if called anytime after other", function() { this.spyB(); this.spyA(); this.spyB(); @@ -1776,44 +1818,44 @@ describe("spy", function () { }); }); - describe(".calledImmediatelyAfter", function () { - beforeEach(function () { + describe(".calledImmediatelyAfter", function() { + beforeEach(function() { this.spyA = createSpy(); this.spyB = createSpy(); this.spyC = createSpy(); }); - it("is function", function () { + it("is function", function() { assert.isFunction(this.spyA.calledImmediatelyAfter); }); - it("returns true if first call to A was immediately after first to B", function () { + it("returns true if first call to A was immediately after first to B", function() { this.spyB(); this.spyA(); assert(this.spyA.calledImmediatelyAfter(this.spyB)); }); - it("compares calls directly", function () { + it("compares calls directly", function() { this.spyB(); this.spyA(); assert(this.spyA.getCall(0).calledImmediatelyAfter(this.spyB.getCall(0))); }); - it("returns false if not called", function () { + it("returns false if not called", function() { this.spyB(); assert.isFalse(this.spyA.calledImmediatelyAfter(this.spyB)); }); - it("returns false if other not called", function () { + it("returns false if other not called", function() { this.spyA(); assert.isFalse(this.spyA.calledImmediatelyAfter(this.spyB)); }); - it("returns false if other called last", function () { + it("returns false if other called last", function() { this.spyB(); this.spyA(); this.spyB(); @@ -1821,7 +1863,7 @@ describe("spy", function () { assert.isFalse(this.spyA.calledImmediatelyAfter(this.spyB)); }); - it("returns false if another spy called between", function () { + it("returns false if another spy called between", function() { this.spyA(); this.spyC(); this.spyB(); @@ -1830,44 +1872,44 @@ describe("spy", function () { }); }); - describe(".calledImmediatelyBefore", function () { - beforeEach(function () { + describe(".calledImmediatelyBefore", function() { + beforeEach(function() { this.spyA = createSpy(); this.spyB = createSpy(); this.spyC = createSpy(); }); - it("is function", function () { + it("is function", function() { assert.isFunction(this.spyA.calledImmediatelyBefore); }); - it("returns true if first call to A was immediately after first to B", function () { + it("returns true if first call to A was immediately after first to B", function() { this.spyB(); this.spyA(); assert(this.spyB.calledImmediatelyBefore(this.spyA)); }); - it("compares calls directly", function () { + it("compares calls directly", function() { this.spyB(); this.spyA(); assert(this.spyB.getCall(0).calledImmediatelyBefore(this.spyA.getCall(0))); }); - it("returns false if not called", function () { + it("returns false if not called", function() { this.spyB(); assert.isFalse(this.spyA.calledImmediatelyBefore(this.spyB)); }); - it("returns false if other not called", function () { + it("returns false if other not called", function() { this.spyA(); assert.isFalse(this.spyA.calledImmediatelyBefore(this.spyB)); }); - it("returns false if other called last", function () { + it("returns false if other called last", function() { this.spyB(); this.spyA(); this.spyB(); @@ -1875,7 +1917,7 @@ describe("spy", function () { assert.isFalse(this.spyB.calledImmediatelyBefore(this.spyA)); }); - it("returns false if another spy called between", function () { + it("returns false if another spy called between", function() { this.spyA(); this.spyC(); this.spyB(); @@ -1884,14 +1926,14 @@ describe("spy", function () { }); }); - describe(".firstCall", function () { - it("is undefined by default", function () { + describe(".firstCall", function() { + it("is undefined by default", function() { var spy = createSpy(); assert.isNull(spy.firstCall); }); - it("is equal to getCall(0) result after first call", function () { + it("is equal to getCall(0) result after first call", function() { var spy = createSpy(); spy(); @@ -1901,7 +1943,7 @@ describe("spy", function () { assert.same(spy.firstCall.spy, call0.spy); }); - it("is equal to getCall(0) after first call when control flow has continued after invocation", function () { + it("is equal to getCall(0) after first call when control flow has continued after invocation", function() { var spy; function runAsserts() { @@ -1915,8 +1957,8 @@ describe("spy", function () { spy(); }); - it("is tracked even if exceptions are thrown", function () { - var spy = createSpy(function () { + it("is tracked even if exceptions are thrown", function() { + var spy = createSpy(function() { throw new Error("an exception"); }); @@ -1925,8 +1967,8 @@ describe("spy", function () { refute.isNull(spy.firstCall); }); - it("has correct returnValue", function () { - var spy = createSpy(function () { + it("has correct returnValue", function() { + var spy = createSpy(function() { return 42; }); @@ -1936,9 +1978,9 @@ describe("spy", function () { assert(spy.firstCall.returned(42)); }); - it("has correct exception", function () { + it("has correct exception", function() { var err = new Error(); - var spy = createSpy(function () { + var spy = createSpy(function() { throw err; }); @@ -1947,24 +1989,23 @@ describe("spy", function () { assert.same(spy.firstCall.exception, err); assert(spy.firstCall.threw(err)); }); - }); - describe(".secondCall", function () { - it("is null by default", function () { + describe(".secondCall", function() { + it("is null by default", function() { var spy = createSpy(); assert.isNull(spy.secondCall); }); - it("stills be null after first call", function () { + it("stills be null after first call", function() { var spy = createSpy(); spy(); assert.isNull(spy.secondCall); }); - it("is equal to getCall(1) result after second call", function () { + it("is equal to getCall(1) result after second call", function() { var spy = createSpy(); spy(); @@ -1976,14 +2017,14 @@ describe("spy", function () { }); }); - describe(".thirdCall", function () { - it("is undefined by default", function () { + describe(".thirdCall", function() { + it("is undefined by default", function() { var spy = createSpy(); assert.isNull(spy.thirdCall); }); - it("stills be undefined after second call", function () { + it("stills be undefined after second call", function() { var spy = createSpy(); spy(); spy(); @@ -1991,7 +2032,7 @@ describe("spy", function () { assert.isNull(spy.thirdCall); }); - it("is equal to getCall(1) result after second call", function () { + it("is equal to getCall(1) result after second call", function() { var spy = createSpy(); spy(); @@ -2004,14 +2045,14 @@ describe("spy", function () { }); }); - describe(".lastCall", function () { - it("is undefined by default", function () { + describe(".lastCall", function() { + it("is undefined by default", function() { var spy = createSpy(); assert.isNull(spy.lastCall); }); - it("is same as firstCall after first call", function () { + it("is same as firstCall after first call", function() { var spy = createSpy(); spy(); @@ -2020,7 +2061,7 @@ describe("spy", function () { assert.same(spy.lastCall.spy, spy.firstCall.spy); }); - it("is same as secondCall after second call", function () { + it("is same as secondCall after second call", function() { var spy = createSpy(); spy(); @@ -2030,7 +2071,7 @@ describe("spy", function () { assert.same(spy.lastCall.spy, spy.secondCall.spy); }); - it("is same as thirdCall after third call", function () { + it("is same as thirdCall after third call", function() { var spy = createSpy(); spy(); @@ -2041,7 +2082,7 @@ describe("spy", function () { assert.same(spy.lastCall.spy, spy.thirdCall.spy); }); - it("is equal to getCall(3) result after fourth call", function () { + it("is equal to getCall(3) result after fourth call", function() { var spy = createSpy(); spy(); @@ -2054,7 +2095,7 @@ describe("spy", function () { assert.same(spy.lastCall.spy, call3.spy); }); - it("is equal to getCall(4) result after fifth call", function () { + it("is equal to getCall(4) result after fifth call", function() { var spy = createSpy(); spy(); @@ -2069,15 +2110,15 @@ describe("spy", function () { }); }); - describe(".getCalls", function () { - it("returns an empty Array by default", function () { + describe(".getCalls", function() { + it("returns an empty Array by default", function() { var spy = createSpy(); assert.isArray(spy.getCalls()); assert.equals(spy.getCalls().length, 0); }); - it("is analogous to using getCall(n)", function () { + it("is analogous to using getCall(n)", function() { var spy = createSpy(); spy(); @@ -2087,14 +2128,14 @@ describe("spy", function () { }); }); - describe(".callArg", function () { - it("is function", function () { + describe(".callArg", function() { + it("is function", function() { var spy = createSpy(); assert.isFunction(spy.callArg); }); - it("invokes argument at index for all calls", function () { + it("invokes argument at index for all calls", function() { var spy = createSpy(); var callback = createSpy(); spy(1, 2, callback); @@ -2106,20 +2147,23 @@ describe("spy", function () { assert(callback.alwaysCalledWith()); }); - it("throws if argument at index is not a function", function () { + it("throws if argument at index is not a function", function() { var spy = createSpy(); spy(); - assert.exception(function () { - spy.callArg(1); - }, {name: "TypeError"}); + assert.exception( + function() { + spy.callArg(1); + }, + { name: "TypeError" } + ); }); - it("throws if spy was not yet invoked", function () { + it("throws if spy was not yet invoked", function() { var spy = createSpy(); assert.exception( - function () { + function() { spy.callArg(0); }, { @@ -2128,12 +2172,16 @@ describe("spy", function () { ); }); - it("includes spy name in error message", function () { - var api = { someMethod: function () { return; } }; + it("includes spy name in error message", function() { + var api = { + someMethod: function() { + return; + } + }; var spy = createSpy(api, "someMethod"); assert.exception( - function () { + function() { spy.callArg(0); }, { @@ -2142,16 +2190,19 @@ describe("spy", function () { ); }); - it("throws if index is not a number", function () { + it("throws if index is not a number", function() { var spy = createSpy(); spy(); - assert.exception(function () { - spy.callArg(""); - }, {name: "TypeError"}); + assert.exception( + function() { + spy.callArg(""); + }, + { name: "TypeError" } + ); }); - it("passs additional arguments", function () { + it("passs additional arguments", function() { var spy = createSpy(); var callback = createSpy(); var array = []; @@ -2163,10 +2214,10 @@ describe("spy", function () { assert(callback.calledWith("abc", 123, array, object)); }); - it("returns callbacks return values for all calls", function () { + it("returns callbacks return values for all calls", function() { var spy = createSpy(); var i = 0; - var callback = createSpy(function () { + var callback = createSpy(function() { i++; return "useful value " + i; }); @@ -2175,21 +2226,18 @@ describe("spy", function () { var returnValues = spy.callArg(2); - assert.equals(returnValues, [ - "useful value 1", - "useful value 2" - ]); + assert.equals(returnValues, ["useful value 1", "useful value 2"]); }); }); - describe(".callArgOn", function () { - it("is function", function () { + describe(".callArgOn", function() { + it("is function", function() { var spy = createSpy(); assert.isFunction(spy.callArgOn); }); - it("invokes argument at index for all calls", function () { + it("invokes argument at index for all calls", function() { var spy = createSpy(); var callback = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -2203,22 +2251,25 @@ describe("spy", function () { assert(callback.alwaysCalledOn(thisObj)); }); - it("throws if argument at index is not a function", function () { + it("throws if argument at index is not a function", function() { var spy = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; spy(); - assert.exception(function () { - spy.callArgOn(1, thisObj); - }, {name: "TypeError"}); + assert.exception( + function() { + spy.callArgOn(1, thisObj); + }, + { name: "TypeError" } + ); }); - it("throws if spy was not yet invoked", function () { + it("throws if spy was not yet invoked", function() { var spy = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.callArgOn(0, thisObj); }, { @@ -2227,13 +2278,17 @@ describe("spy", function () { ); }); - it("includes spy name in error message", function () { - var api = { someMethod: function () { return; } }; + it("includes spy name in error message", function() { + var api = { + someMethod: function() { + return; + } + }; var spy = createSpy(api, "someMethod"); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.callArgOn(0, thisObj); }, { @@ -2242,17 +2297,20 @@ describe("spy", function () { ); }); - it("throws if index is not a number", function () { + it("throws if index is not a number", function() { var spy = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; spy(); - assert.exception(function () { - spy.callArg("", thisObj); - }, {name: "TypeError"}); + assert.exception( + function() { + spy.callArg("", thisObj); + }, + { name: "TypeError" } + ); }); - it("pass additional arguments", function () { + it("pass additional arguments", function() { var spy = createSpy(); var callback = createSpy(); var array = []; @@ -2266,10 +2324,10 @@ describe("spy", function () { assert(callback.calledOn(thisObj)); }); - it("returns callbacks return values for all calls", function () { + it("returns callbacks return values for all calls", function() { var spy = createSpy(); var i = 0; - var callback = createSpy(function () { + var callback = createSpy(function() { i++; return "useful value " + i; }); @@ -2279,37 +2337,34 @@ describe("spy", function () { var returnValues = spy.callArgOn(2, thisObj); - assert.equals(returnValues, [ - "useful value 1", - "useful value 2" - ]); + assert.equals(returnValues, ["useful value 1", "useful value 2"]); }); }); - describe(".callArgWith", function () { - it("is alias for callArg", function () { + describe(".callArgWith", function() { + it("is alias for callArg", function() { var spy = createSpy(); assert.same(spy.callArgWith, spy.callArg); }); }); - describe(".callArgOnWith", function () { - it("is alias for callArgOn", function () { + describe(".callArgOnWith", function() { + it("is alias for callArgOn", function() { var spy = createSpy(); assert.same(spy.callArgOnWith, spy.callArgOn); }); }); - describe(".yield", function () { - it("is function", function () { + describe(".yield", function() { + it("is function", function() { var spy = createSpy(); assert.isFunction(spy.yield); }); - it("invokes first function arg for all calls", function () { + it("invokes first function arg for all calls", function() { var spy = createSpy(); var callback = createSpy(); spy(1, 2, callback); @@ -2321,11 +2376,11 @@ describe("spy", function () { assert(callback.alwaysCalledWith()); }); - it("throws if spy was not yet invoked", function () { + it("throws if spy was not yet invoked", function() { var spy = createSpy(); assert.exception( - function () { + function() { spy.yield(); }, { @@ -2334,12 +2389,16 @@ describe("spy", function () { ); }); - it("includes spy name in error message", function () { - var api = { someMethod: function () { return; } }; + it("includes spy name in error message", function() { + var api = { + someMethod: function() { + return; + } + }; var spy = createSpy(api, "someMethod"); assert.exception( - function () { + function() { spy.yield(); }, { @@ -2348,7 +2407,7 @@ describe("spy", function () { ); }); - it("passs additional arguments", function () { + it("passs additional arguments", function() { var spy = createSpy(); var callback = createSpy(); var array = []; @@ -2360,10 +2419,10 @@ describe("spy", function () { assert(callback.calledWith("abc", 123, array, object)); }); - it("returns callbacks return values for all calls", function () { + it("returns callbacks return values for all calls", function() { var spy = createSpy(); var i = 0; - var callback = createSpy(function () { + var callback = createSpy(function() { i++; return "useful value " + i; }); @@ -2372,29 +2431,26 @@ describe("spy", function () { var returnValues = spy.yield(); - assert.equals(returnValues, [ - "useful value 1", - "useful value 2" - ]); + assert.equals(returnValues, ["useful value 1", "useful value 2"]); }); }); - describe(".invokeCallback", function () { - it("is alias for yield", function () { + describe(".invokeCallback", function() { + it("is alias for yield", function() { var spy = createSpy(); assert.same(spy.invokeCallback, spy.yield); }); }); - describe(".yieldOn", function () { - it("is function", function () { + describe(".yieldOn", function() { + it("is function", function() { var spy = createSpy(); assert.isFunction(spy.yieldOn); }); - it("invokes first function arg for all calls", function () { + it("invokes first function arg for all calls", function() { var spy = createSpy(); var callback = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -2408,12 +2464,12 @@ describe("spy", function () { assert(callback.alwaysCalledOn(thisObj)); }); - it("throws if spy was not yet invoked", function () { + it("throws if spy was not yet invoked", function() { var spy = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.yieldOn(thisObj); }, { @@ -2422,13 +2478,17 @@ describe("spy", function () { ); }); - it("includes spy name in error message", function () { - var api = { someMethod: function () { return; } }; + it("includes spy name in error message", function() { + var api = { + someMethod: function() { + return; + } + }; var spy = createSpy(api, "someMethod"); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.yieldOn(thisObj); }, { @@ -2437,7 +2497,7 @@ describe("spy", function () { ); }); - it("pass additional arguments", function () { + it("pass additional arguments", function() { var spy = createSpy(); var callback = createSpy(); var array = []; @@ -2451,10 +2511,10 @@ describe("spy", function () { assert(callback.calledOn(thisObj)); }); - it("returns callbacks return values for all calls", function () { + it("returns callbacks return values for all calls", function() { var spy = createSpy(); var i = 0; - var callback = createSpy(function () { + var callback = createSpy(function() { i++; return "useful value " + i; }); @@ -2464,21 +2524,18 @@ describe("spy", function () { var returnValues = spy.yieldOn(thisObj); - assert.equals(returnValues, [ - "useful value 1", - "useful value 2" - ]); + assert.equals(returnValues, ["useful value 1", "useful value 2"]); }); }); - describe(".yieldTo", function () { - it("is function", function () { + describe(".yieldTo", function() { + it("is function", function() { var spy = createSpy(); assert.isFunction(spy.yieldTo); }); - it("invokes first function arg for all calls", function () { + it("invokes first function arg for all calls", function() { var spy = createSpy(); var callback = createSpy(); spy(1, 2, { success: callback }); @@ -2490,11 +2547,11 @@ describe("spy", function () { assert(callback.alwaysCalledWith()); }); - it("throws if spy was not yet invoked", function () { + it("throws if spy was not yet invoked", function() { var spy = createSpy(); assert.exception( - function () { + function() { spy.yieldTo("success"); }, { @@ -2503,12 +2560,16 @@ describe("spy", function () { ); }); - it("includes spy name in error message", function () { - var api = { someMethod: function () { return; } }; + it("includes spy name in error message", function() { + var api = { + someMethod: function() { + return; + } + }; var spy = createSpy(api, "someMethod"); assert.exception( - function () { + function() { spy.yieldTo("success"); }, { @@ -2517,12 +2578,12 @@ describe("spy", function () { ); }); - it("throws readable message for symbol when spy was not yet invoked", function () { + it("throws readable message for symbol when spy was not yet invoked", function() { if (typeof Symbol === "function") { var spy = createSpy(); assert.exception( - function () { + function() { spy.yieldTo(Symbol()); }, { @@ -2532,7 +2593,7 @@ describe("spy", function () { } }); - it("pass additional arguments", function () { + it("pass additional arguments", function() { var spy = createSpy(); var callback = createSpy(); var array = []; @@ -2544,10 +2605,10 @@ describe("spy", function () { assert(callback.calledWith("abc", 123, array, object)); }); - it("returns callbacks return values for all calls", function () { + it("returns callbacks return values for all calls", function() { var spy = createSpy(); var i = 0; - var callback = createSpy(function () { + var callback = createSpy(function() { i++; return "useful value " + i; }); @@ -2556,21 +2617,18 @@ describe("spy", function () { var returnValues = spy.yieldTo("success"); - assert.equals(returnValues, [ - "useful value 1", - "useful value 2" - ]); + assert.equals(returnValues, ["useful value 1", "useful value 2"]); }); }); - describe(".yieldToOn", function () { - it("is function", function () { + describe(".yieldToOn", function() { + it("is function", function() { var spy = createSpy(); assert.isFunction(spy.yieldToOn); }); - it("invokes first function arg for all calls", function () { + it("invokes first function arg for all calls", function() { var spy = createSpy(); var callback = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; @@ -2584,12 +2642,12 @@ describe("spy", function () { assert(callback.alwaysCalledOn(thisObj)); }); - it("throws if spy was not yet invoked", function () { + it("throws if spy was not yet invoked", function() { var spy = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.yieldToOn("success", thisObj); }, { @@ -2598,13 +2656,17 @@ describe("spy", function () { ); }); - it("includes spy name in error message", function () { - var api = { someMethod: function () { return; } }; + it("includes spy name in error message", function() { + var api = { + someMethod: function() { + return; + } + }; var spy = createSpy(api, "someMethod"); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.yieldToOn("success", thisObj); }, { @@ -2613,13 +2675,13 @@ describe("spy", function () { ); }); - it("throws readable message for symbol when spy was not yet invoked", function () { + it("throws readable message for symbol when spy was not yet invoked", function() { if (typeof Symbol === "function") { var spy = createSpy(); var thisObj = { name1: "value1", name2: "value2" }; assert.exception( - function () { + function() { spy.yieldToOn(Symbol(), thisObj); }, { @@ -2629,7 +2691,7 @@ describe("spy", function () { } }); - it("pass additional arguments", function () { + it("pass additional arguments", function() { var spy = createSpy(); var callback = createSpy(); var array = []; @@ -2643,10 +2705,10 @@ describe("spy", function () { assert(callback.calledOn(thisObj)); }); - it("returns callbacks return values for all calls", function () { + it("returns callbacks return values for all calls", function() { var spy = createSpy(); var i = 0; - var callback = createSpy(function () { + var callback = createSpy(function() { i++; return "useful value " + i; }); @@ -2656,76 +2718,71 @@ describe("spy", function () { var returnValues = spy.yieldToOn("success", thisObj); - assert.equals(returnValues, [ - "useful value 1", - "useful value 2" - ]); + assert.equals(returnValues, ["useful value 1", "useful value 2"]); }); }); - describe(".throwArg", function () { - it("should be a function", function () { + describe(".throwArg", function() { + it("should be a function", function() { var spy = createSpy(); assert.isFunction(spy.throwArg); }); - it("should throw if spy hasn't been called", function () { + it("should throw if spy hasn't been called", function() { var spy = createSpy(); assert.exception( - function () { + function() { spy.throwArg(0); }, - function (error) { + function(error) { return error.message === "spy cannot throw arg since it was not yet invoked."; } ); }); - it("should throw if there aren't enough arguments in the previous spy call", function () { + it("should throw if there aren't enough arguments in the previous spy call", function() { var spy = createSpy(); spy("only", "four", "arguments", "here"); assert.exception( - function () { + function() { spy.throwArg(7); }, - function (error) { + function(error) { return error.message === "Not enough arguments: 7 required but only 4 present"; } ); }); - it("should throw specified argument", function () { + it("should throw specified argument", function() { var spy = createSpy(); var expectedError = new TypeError("catpants"); spy(true, false, null, expectedError, "meh"); assert.exception( - function () { + function() { spy.throwArg(3); }, - function (error) { - return error instanceof TypeError - && error.message === expectedError.message - ; + function(error) { + return error instanceof TypeError && error.message === expectedError.message; } ); }); }); - describe(".resetHistory", function () { - it("return same object", function () { + describe(".resetHistory", function() { + it("return same object", function() { var spy = createSpy(); var reset = spy.resetHistory(); assert(reset === spy); }); - it("throws if called during spy invocation", function () { - var spy = createSpy(function () { + it("throws if called during spy invocation", function() { + var spy = createSpy(function() { spy.resetHistory(); }); @@ -2733,37 +2790,42 @@ describe("spy", function () { }); }); - describe(".length", function () { - it("is zero by default", function () { + describe(".length", function() { + it("is zero by default", function() { var spy = createSpy(); assert.equals(spy.length, 0); }); - it("matches the function length", function () { - var api = { someMethod: function (a, b, c) { return; } }; // eslint-disable-line no-unused-vars + it("matches the function length", function() { + var api = { + // eslint-disable-next-line no-unused-vars + someMethod: function(a, b, c) { + return; + } + }; var spy = createSpy(api, "someMethod"); assert.equals(spy.length, 3); }); }); - describe(".matchingFakes", function () { - beforeEach(function () { + describe(".matchingFakes", function() { + beforeEach(function() { this.spy = createSpy(); }); - it("is function", function () { + it("is function", function() { assert.isFunction(this.spy.matchingFakes); }); - it("returns an empty array by default", function () { + it("returns an empty array by default", function() { assert.equals(this.spy.matchingFakes([]), []); assert.equals(this.spy.matchingFakes([1]), []); assert.equals(this.spy.matchingFakes([1, 1]), []); }); - it("returns one matched fake", function () { + it("returns one matched fake", function() { this.spy.withArgs(1); this.spy.withArgs(2); @@ -2771,28 +2833,22 @@ describe("spy", function () { assert.equals(this.spy.matchingFakes([2]), [this.spy.withArgs(2)]); }); - it("return some matched fake", function () { + it("return some matched fake", function() { this.spy.withArgs(1); this.spy.withArgs(1, 1); this.spy.withArgs(2); assert.equals(this.spy.matchingFakes([]), []); - assert.equals(this.spy.matchingFakes([1]), [ - this.spy.withArgs(1) - ]); - assert.equals(this.spy.matchingFakes([1, 1]), [ - this.spy.withArgs(1), - this.spy.withArgs(1, 1) - ]); + assert.equals(this.spy.matchingFakes([1]), [this.spy.withArgs(1)]); + assert.equals(this.spy.matchingFakes([1, 1]), [this.spy.withArgs(1), this.spy.withArgs(1, 1)]); }); }); - describe(".id", function () { - it("should start with 'spy#'", function () { + describe(".id", function() { + it("should start with 'spy#'", function() { for (var i = 0; i < 10; i++) { assert.isTrue(createSpy().id.indexOf("spy#") === 0); } }); }); }); - diff --git a/test/stub-test.js b/test/stub-test.js index abe66fa48..b9a42836a 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -11,18 +11,18 @@ var refute = referee.refute; var fail = referee.fail; var Promise = require("native-promise-only"); // eslint-disable-line no-unused-vars -describe("stub", function () { - beforeEach(function () { +describe("stub", function() { + beforeEach(function() { createStub(deprecated, "printWarning"); }); - afterEach(function () { + afterEach(function() { if (deprecated.printWarning.restore) { deprecated.printWarning.restore(); } }); - it("is spy", function () { + it("is spy", function() { var stub = createStub.create(); assert.isFalse(stub.called); @@ -30,9 +30,9 @@ describe("stub", function () { assert.isFunction(stub.calledOn); }); - it("fails if stubbing property on null", function () { + it("fails if stubbing property on null", function() { assert.exception( - function () { + function() { createStub(null, "prop"); }, { @@ -41,10 +41,10 @@ describe("stub", function () { ); }); - it("throws a readable error if stubbing Symbol on null", function () { + it("throws a readable error if stubbing Symbol on null", function() { if (typeof Symbol === "function") { assert.exception( - function () { + function() { createStub(null, Symbol()); }, { @@ -54,7 +54,7 @@ describe("stub", function () { } }); - it("should contain asynchronous versions of callsArg*, and yields* methods", function () { + it("should contain asynchronous versions of callsArg*, and yields* methods", function() { var stub = createStub.create(); var syncVersions = 0; @@ -70,11 +70,14 @@ describe("stub", function () { } } - assert.same(syncVersions, asyncVersions, - "Stub prototype should contain same amount of synchronous and asynchronous methods"); + assert.same( + syncVersions, + asyncVersions, + "Stub prototype should contain same amount of synchronous and asynchronous methods" + ); }); - it("should allow overriding async behavior with sync behavior", function () { + it("should allow overriding async behavior with sync behavior", function() { var stub = createStub(); var callback = createSpy(); @@ -85,7 +88,7 @@ describe("stub", function () { assert(callback.called); }); - it("should works with combination of withArgs arguments", function () { + it("should works with combination of withArgs arguments", function() { var stub = createStub(); stub.returns(0); stub.withArgs(1, 1).returns(2); @@ -98,7 +101,7 @@ describe("stub", function () { assert.equals(stub(2), 0); }); - it("should work with combination of withArgs arguments", function () { + it("should work with combination of withArgs arguments", function() { var stub = createStub(); stub.withArgs(1).returns(42); @@ -107,8 +110,8 @@ describe("stub", function () { refute.isNull(stub.withArgs(1).firstCall); }); - describe(".returns", function () { - it("returns specified value", function () { + describe(".returns", function() { + it("returns specified value", function() { var stub = createStub.create(); var object = {}; stub.returns(object); @@ -116,33 +119,33 @@ describe("stub", function () { assert.same(stub(), object); }); - it("returns should return stub", function () { + it("returns should return stub", function() { var stub = createStub.create(); assert.same(stub.returns(""), stub); }); - it("returns undefined", function () { + it("returns undefined", function() { var stub = createStub.create(); refute.defined(stub()); }); - it("supersedes previous throws", function () { + it("supersedes previous throws", function() { var stub = createStub.create(); stub.throws().returns(1); - refute.exception(function () { + refute.exception(function() { stub(); }); }); - it("throws only on the first call", function () { + it("throws only on the first call", function() { var stub = createStub.create(); stub.returns("no exception"); stub.onFirstCall().throws(); - assert.exception(function () { + assert.exception(function() { stub(); }); @@ -151,53 +154,53 @@ describe("stub", function () { }); }); - describe(".resolves", function () { - afterEach(function () { + describe(".resolves", function() { + afterEach(function() { if (Promise.resolve.restore) { Promise.resolve.restore(); } }); - it("returns a promise to the specified value", function () { + it("returns a promise to the specified value", function() { var stub = createStub.create(); var object = {}; stub.resolves(object); - return stub().then(function (actual) { + return stub().then(function(actual) { assert.same(actual, object); }); }); - it("should return the same stub", function () { + it("should return the same stub", function() { var stub = createStub.create(); assert.same(stub.resolves(""), stub); }); - it("supersedes previous throws", function () { + it("supersedes previous throws", function() { var stub = createStub.create(); stub.throws().resolves(1); - refute.exception(function () { + refute.exception(function() { stub(); }); }); - it("supersedes previous rejects", function () { + it("supersedes previous rejects", function() { var stub = createStub.create(); stub.rejects(Error("should be superseeded")).resolves(1); return stub().then(); }); - it("can be superseded by returns", function () { + it("can be superseded by returns", function() { var stub = createStub.create(); stub.resolves(2).returns(1); assert.equals(stub(), 1); }); - it("does not invoke Promise.resolve when the behavior is added to the stub", function () { + it("does not invoke Promise.resolve when the behavior is added to the stub", function() { var resolveSpy = createSpy(Promise, "resolve"); var stub = createStub.create(); stub.resolves(2); @@ -206,73 +209,81 @@ describe("stub", function () { }); }); - describe(".rejects", function () { - afterEach(function () { + describe(".rejects", function() { + afterEach(function() { if (Promise.reject.restore) { Promise.reject.restore(); } }); - it("returns a promise which rejects for the specified reason", function () { + it("returns a promise which rejects for the specified reason", function() { var stub = createStub.create(); var reason = new Error(); stub.rejects(reason); - return stub().then(function () { - referee.fail("this should not resolve"); - }).catch(function (actual) { - assert.same(actual, reason); - }); + return stub() + .then(function() { + referee.fail("this should not resolve"); + }) + .catch(function(actual) { + assert.same(actual, reason); + }); }); - it("should return the same stub", function () { + it("should return the same stub", function() { var stub = createStub.create(); assert.same(stub.rejects({}), stub); }); - it("specifies exception message", function () { + it("specifies exception message", function() { var stub = createStub.create(); var message = "Oh no!"; stub.rejects("Error", message); - return stub().then(function () { - referee.fail("Expected stub to reject"); - }).catch(function (reason) { - assert.equals(reason.message, message); - }); + return stub() + .then(function() { + referee.fail("Expected stub to reject"); + }) + .catch(function(reason) { + assert.equals(reason.message, message); + }); }); - it("does not specify exception message if not provided", function () { + it("does not specify exception message if not provided", function() { var stub = createStub.create(); stub.rejects("Error"); - return stub().then(function () { - referee.fail("Expected stub to reject"); - }).catch(function (reason) { - assert.equals(reason.message, ""); - }); + return stub() + .then(function() { + referee.fail("Expected stub to reject"); + }) + .catch(function(reason) { + assert.equals(reason.message, ""); + }); }); - it("rejects for a generic reason", function () { + it("rejects for a generic reason", function() { var stub = createStub.create(); stub.rejects(); - return stub().then(function () { - referee.fail("Expected stub to reject"); - }).catch(function (reason) { - assert.equals(reason.name, "Error"); - }); + return stub() + .then(function() { + referee.fail("Expected stub to reject"); + }) + .catch(function(reason) { + assert.equals(reason.name, "Error"); + }); }); - it("can be superseded by returns", function () { + it("can be superseded by returns", function() { var stub = createStub.create(); stub.rejects(2).returns(1); assert.equals(stub(), 1); }); - it("does not invoke Promise.reject when the behavior is added to the stub", function () { + it("does not invoke Promise.reject when the behavior is added to the stub", function() { var rejectSpy = createSpy(Promise, "reject"); var stub = createStub.create(); stub.rejects(2); @@ -281,120 +292,126 @@ describe("stub", function () { }); }); - describe(".resolvesThis", function () { - afterEach(function () { + describe(".resolvesThis", function() { + afterEach(function() { if (Promise.resolve.restore) { Promise.resolve.restore(); } }); - it("returns a promise resolved with this", function () { + it("returns a promise resolved with this", function() { var instance = {}; instance.stub = createStub.create(); instance.stub.resolvesThis(); - return instance.stub().then(function (actual) { + return instance.stub().then(function(actual) { assert.same(actual, instance); }); }); - it("returns a promise resolved with the context bound with stub#call", function () { + it("returns a promise resolved with the context bound with stub#call", function() { var stub = createStub.create(); stub.resolvesThis(); var object = {}; - return stub.call(object).then(function (actual) { + return stub.call(object).then(function(actual) { assert.same(actual, object); }); }); - it("returns a promise resolved with the context bound with stub#apply", function () { + it("returns a promise resolved with the context bound with stub#apply", function() { var stub = createStub.create(); stub.resolvesThis(); var object = {}; - return stub.apply(object).then(function (actual) { + return stub.apply(object).then(function(actual) { assert.same(actual, object); }); }); - it("returns the stub itself, allowing to chain function calls", function () { + it("returns the stub itself, allowing to chain function calls", function() { var stub = createStub.create(); assert.same(stub.resolvesThis(), stub); }); - it("overrides throws behavior for error objects", function () { + it("overrides throws behavior for error objects", function() { var instance = {}; - instance.stub = createStub.create().throws(new Error()).resolvesThis(); + instance.stub = createStub + .create() + .throws(new Error()) + .resolvesThis(); - return instance.stub().then(function (actual) { + return instance.stub().then(function(actual) { assert.same(actual, instance); }); }); - it("overrides throws behavior for dynamically created errors", function () { + it("overrides throws behavior for dynamically created errors", function() { var instance = {}; - instance.stub = createStub.create().throws().resolvesThis(); + instance.stub = createStub + .create() + .throws() + .resolvesThis(); - return instance.stub().then(function (actual) { + return instance.stub().then(function(actual) { assert.same(actual, instance); }); }); }); - describe(".resolvesArg", function () { - afterEach(function () { + describe(".resolvesArg", function() { + afterEach(function() { if (Promise.resolve.restore) { Promise.resolve.restore(); } }); - it("returns a promise to the argument at specified index", function () { + it("returns a promise to the argument at specified index", function() { var stub = createStub.create(); var object = {}; stub.resolvesArg(0); - return stub(object).then(function (actual) { + return stub(object).then(function(actual) { assert.same(actual, object); }); }); - it("returns a promise to the argument at another specified index", function () { + it("returns a promise to the argument at another specified index", function() { var stub = createStub.create(); var object = {}; stub.resolvesArg(2); - return stub("ignored", "ignored again", object).then(function (actual) { + return stub("ignored", "ignored again", object).then(function(actual) { assert.same(actual, object); }); }); - it("should return the same stub", function () { + it("should return the same stub", function() { var stub = createStub.create(); assert.same(stub.resolvesArg(1), stub); }); - it("supersedes previous throws", function () { + it("supersedes previous throws", function() { var stub = createStub.create(); stub.throws().resolvesArg(1); - refute.exception(function () { + refute.exception(function() { stub("zero", "one"); }); }); - it("supersedes previous rejects", function () { + it("supersedes previous rejects", function() { var stub = createStub.create(); stub.rejects(Error("should be superseeded")).resolvesArg(1); - return stub("zero", "one").then(function (actual) { + return stub("zero", "one").then(function(actual) { assert.same(actual, "one"); }); }); - it("does not invoke Promise.resolve when the behavior is added to the stub", function () { + it("does not invoke Promise.resolve when the behavior is added to the stub", function() { var resolveSpy = createSpy(Promise, "resolve"); var stub = createStub.create(); stub.resolvesArg(2); @@ -402,29 +419,35 @@ describe("stub", function () { assert(resolveSpy.notCalled); }); - it("throws if index is not a number", function () { + it("throws if index is not a number", function() { var stub = createStub.create(); - assert.exception(function () { - stub.resolvesArg(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.resolvesArg(); + }, + { name: "TypeError" } + ); }); - it("throws without enough arguments", function () { + it("throws without enough arguments", function() { var stub = createStub.create(); stub.resolvesArg(3); - assert.exception(function () { - stub("zero", "one", "two"); - }, { - name: "TypeError", - message: "resolvesArg failed: 4 arguments required but only 3 present" - }); + assert.exception( + function() { + stub("zero", "one", "two"); + }, + { + name: "TypeError", + message: "resolvesArg failed: 4 arguments required but only 3 present" + } + ); }); }); - describe(".returnsArg", function () { - it("returns argument at specified index", function () { + describe(".returnsArg", function() { + it("returns argument at specified index", function() { var stub = createStub.create(); stub.returnsArg(0); var object = {}; @@ -432,26 +455,29 @@ describe("stub", function () { assert.same(stub(object), object); }); - it("returns stub", function () { + it("returns stub", function() { var stub = createStub.create(); assert.same(stub.returnsArg(0), stub); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var stub = createStub.create(); - assert.exception(function () { - stub.returnsArg(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.returnsArg(); + }, + { name: "TypeError" } + ); }); - it("should throw without enough arguments", function () { + it("should throw without enough arguments", function() { var stub = createStub.create(); stub.returnsArg(3); assert.exception( - function () { + function() { stub("only", "two arguments"); }, { @@ -462,39 +488,45 @@ describe("stub", function () { }); }); - describe(".throwsArg", function () { - it("throws argument at specified index", function () { + describe(".throwsArg", function() { + it("throws argument at specified index", function() { var stub = createStub.create(); stub.throwsArg(0); var expectedError = new Error("The expected error message"); - assert.exception(function () { - stub(expectedError); - }, function (err) { - return err.message === expectedError.message; - }); + assert.exception( + function() { + stub(expectedError); + }, + function(err) { + return err.message === expectedError.message; + } + ); }); - it("returns stub", function () { + it("returns stub", function() { var stub = createStub.create(); assert.same(stub.throwsArg(0), stub); }); - it("throws TypeError if no index is specified", function () { + it("throws TypeError if no index is specified", function() { var stub = createStub.create(); - assert.exception(function () { - stub.throwsArg(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.throwsArg(); + }, + { name: "TypeError" } + ); }); - it("should throw without enough arguments", function () { + it("should throw without enough arguments", function() { var stub = createStub.create(); stub.throwsArg(3); assert.exception( - function () { + function() { stub("only", "two arguments"); }, { @@ -504,41 +536,41 @@ describe("stub", function () { ); }); - it("should work with call-based behavior", function () { + it("should work with call-based behavior", function() { var stub = createStub.create(); var expectedError = new Error("catpants"); stub.returns(1); stub.onSecondCall().throwsArg(1); - refute.exception(function () { + refute.exception(function() { assert.equals(1, stub(null, expectedError)); }); assert.exception( - function () { + function() { stub(null, expectedError); }, - function (error) { + function(error) { return error.message === expectedError.message; } ); }); - it("should be reset by .resetBeahvior", function () { + it("should be reset by .resetBeahvior", function() { var stub = createStub.create(); stub.throwsArg(0); stub.resetBehavior(); - refute.exception(function () { + refute.exception(function() { stub(new Error("catpants")); }); }); }); - describe(".returnsThis", function () { - it("stub returns this", function () { + describe(".returnsThis", function() { + it("stub returns this", function() { var instance = {}; instance.stub = createStub.create(); instance.stub.returnsThis(); @@ -546,11 +578,12 @@ describe("stub", function () { assert.same(instance.stub(), instance); }); - var strictMode = (function () { - return this; - }()) === undefined; + var strictMode = + (function() { + return this; + })() === undefined; if (strictMode) { - it("stub returns undefined when detached", function () { + it("stub returns undefined when detached", function() { var stub = createStub.create(); stub.returnsThis(); @@ -559,7 +592,7 @@ describe("stub", function () { }); } - it("stub respects call/apply", function () { + it("stub respects call/apply", function() { var stub = createStub.create(); stub.returnsThis(); var object = {}; @@ -568,31 +601,31 @@ describe("stub", function () { assert.same(stub.apply(object), object); }); - it("returns stub", function () { + it("returns stub", function() { var stub = createStub.create(); assert.same(stub.returnsThis(), stub); }); }); - describe(".usingPromise", function () { - it("should exist and be a function", function () { + describe(".usingPromise", function() { + it("should exist and be a function", function() { var stub = createStub.create(); assert(stub.usingPromise); assert.isFunction(stub.usingPromise); }); - it("should return the current stub", function () { + it("should return the current stub", function() { var stub = createStub.create(); assert.same(stub.usingPromise(Promise), stub); }); - it("should set the promise used by resolve", function () { + it("should set the promise used by resolve", function() { var stub = createStub.create(); var promise = { - resolve: createStub.create().callsFake(function (value) { + resolve: createStub.create().callsFake(function(value) { return Promise.resolve(value); }) }; @@ -600,17 +633,17 @@ describe("stub", function () { stub.usingPromise(promise).resolves(object); - return stub().then(function (actual) { + return stub().then(function(actual) { assert.same(actual, object, "Same object resolved"); assert.isTrue(promise.resolve.calledOnce, "Custom promise resolve called once"); assert.isTrue(promise.resolve.calledWith(object), "Custom promise resolve called once with expected"); }); }); - it("should set the promise used by reject", function () { + it("should set the promise used by reject", function() { var stub = createStub.create(); var promise = { - reject: createStub.create().callsFake(function (err) { + reject: createStub.create().callsFake(function(err) { return Promise.reject(err); }) }; @@ -618,18 +651,20 @@ describe("stub", function () { stub.usingPromise(promise).rejects(reason); - return stub().then(function () { - referee.fail("this should not resolve"); - }).catch(function (actual) { - assert.same(actual, reason, "Same object resolved"); - assert.isTrue(promise.reject.calledOnce, "Custom promise reject called once"); - assert.isTrue(promise.reject.calledWith(reason), "Custom promise reject called once with expected"); - }); + return stub() + .then(function() { + referee.fail("this should not resolve"); + }) + .catch(function(actual) { + assert.same(actual, reason, "Same object resolved"); + assert.isTrue(promise.reject.calledOnce, "Custom promise reject called once"); + assert.isTrue(promise.reject.calledWith(reason), "Custom promise reject called once with expected"); + }); }); }); - describe(".throws", function () { - it("throws specified exception", function () { + describe(".throws", function() { + it("throws specified exception", function() { var stub = createStub.create(); var error = new Error(); stub.throws(error); @@ -637,23 +672,23 @@ describe("stub", function () { assert.exception(stub, error); }); - it("returns stub", function () { + it("returns stub", function() { var stub = createStub.create(); assert.same(stub.throws({}), stub); }); - it("sets type of exception to throw", function () { + it("sets type of exception to throw", function() { var stub = createStub.create(); var exceptionType = "TypeError"; stub.throws(exceptionType); - assert.exception(function () { + assert.exception(function() { stub(); }, exceptionType); }); - it("specifies exception message", function () { + it("specifies exception message", function() { var stub = createStub.create(); var message = "Oh no!"; stub.throws("Error", message); @@ -663,7 +698,7 @@ describe("stub", function () { }); }); - it("does not specify exception message if not provided", function () { + it("does not specify exception message if not provided", function() { var stub = createStub.create(); stub.throws("Error"); @@ -672,17 +707,17 @@ describe("stub", function () { }); }); - it("throws generic error", function () { + it("throws generic error", function() { var stub = createStub.create(); stub.throws(); assert.exception(stub, "Error"); }); - it("throws an exception created using a function", function () { + it("throws an exception created using a function", function() { var stub = createStub.create(); - stub.throws(function () { + stub.throws(function() { return new Error("not implemented"); }); @@ -693,21 +728,21 @@ describe("stub", function () { assert.contains(stub.firstCall.toString(), "not implemented"); }); - describe("lazy instantiation of exceptions", function () { + describe("lazy instantiation of exceptions", function() { var errorSpy; - beforeEach(function () { + beforeEach(function() { this.originalError = global.Error; errorSpy = createSpy(global, "Error"); // errorSpy starts with a call already made, not sure why errorSpy.resetHistory(); }); - afterEach(function () { + afterEach(function() { errorSpy.restore(); global.Error = this.originalError; }); - it("uses a lazily created exception for the generic error", function () { + it("uses a lazily created exception for the generic error", function() { var stub = createStub.create(); stub.throws(); @@ -716,7 +751,7 @@ describe("stub", function () { assert.isTrue(errorSpy.called); }); - it("uses a lazily created exception for the named error", function () { + it("uses a lazily created exception for the named error", function() { var stub = createStub.create(); stub.throws("Named Error", "error message"); @@ -728,10 +763,10 @@ describe("stub", function () { assert.isTrue(errorSpy.called); }); - it("uses a lazily created exception provided by a function", function () { + it("uses a lazily created exception provided by a function", function() { var stub = createStub.create(); - stub.throws(function () { + stub.throws(function() { return new Error("not implemented"); }); @@ -742,7 +777,7 @@ describe("stub", function () { assert.isTrue(errorSpy.called); }); - it("does not use a lazily created exception if the error object is provided", function () { + it("does not use a lazily created exception if the error object is provided", function() { var stub = createStub.create(); var exception = new Error(); stub.throws(exception); @@ -753,7 +788,7 @@ describe("stub", function () { }); }); - it("resets 'invoking' flag", function () { + it("resets 'invoking' flag", function() { var stub = createStub.create(); stub.throws(); @@ -763,12 +798,12 @@ describe("stub", function () { }); }); - describe(".callsArg", function () { - beforeEach(function () { + describe(".callsArg", function() { + beforeEach(function() { this.stub = createStub.create(); }); - it("calls argument at specified index", function () { + it("calls argument at specified index", function() { this.stub.callsArg(2); var callback = createStub.create(); @@ -777,40 +812,49 @@ describe("stub", function () { assert(callback.called); }); - it("returns stub", function () { + it("returns stub", function() { assert.isFunction(this.stub.callsArg(2)); }); - it("throws if argument at specified index is not callable", function () { + it("throws if argument at specified index is not callable", function() { this.stub.callsArg(0); - assert.exception(function () { - this.stub(1); - }, {name: "TypeError"}); + assert.exception( + function() { + this.stub(1); + }, + { name: "TypeError" } + ); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArg(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArg(); + }, + { name: "TypeError" } + ); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArg({}); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArg({}); + }, + { name: "TypeError" } + ); }); - it("should throw without enough arguments", function () { + it("should throw without enough arguments", function() { var stub = createStub.create(); stub.callsArg(3); assert.exception( - function () { + function() { stub("only", "two arguments"); }, { @@ -820,7 +864,7 @@ describe("stub", function () { ); }); - it("returns result of invocant", function () { + it("returns result of invocant", function() { var stub = this.stub.callsArg(0); var callback = createStub().returns("return value"); @@ -829,12 +873,12 @@ describe("stub", function () { }); }); - describe(".callsArgWith", function () { - beforeEach(function () { + describe(".callsArgWith", function() { + beforeEach(function() { this.stub = createStub.create(); }); - it("calls argument at specified index with provided args", function () { + it("calls argument at specified index with provided args", function() { var object = {}; this.stub.callsArgWith(1, object); var callback = createStub.create(); @@ -844,13 +888,13 @@ describe("stub", function () { assert(callback.calledWith(object)); }); - it("returns function", function () { + it("returns function", function() { var stub = this.stub.callsArgWith(2, 3); assert.isFunction(stub); }); - it("calls callback without args", function () { + it("calls callback without args", function() { this.stub.callsArgWith(1); var callback = createStub.create(); @@ -859,7 +903,7 @@ describe("stub", function () { assert(callback.calledWith()); }); - it("calls callback with multiple args", function () { + it("calls callback with multiple args", function() { var object = {}; var array = []; this.stub.callsArgWith(1, object, array); @@ -870,23 +914,29 @@ describe("stub", function () { assert(callback.calledWith(object, array)); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArgWith(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArgWith(); + }, + { name: "TypeError" } + ); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArgWith({}); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArgWith({}); + }, + { name: "TypeError" } + ); }); - it("returns result of invocant", function () { + it("returns result of invocant", function() { var stub = this.stub.callsArgWith(0, "test"); var callback = createStub().returns("return value"); @@ -895,15 +945,15 @@ describe("stub", function () { }); }); - describe(".callsArgOn", function () { - beforeEach(function () { + describe(".callsArgOn", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("calls argument at specified index", function () { + it("calls argument at specified index", function() { this.stub.callsArgOn(2, this.fakeContext); var callback = createStub.create(); @@ -913,7 +963,7 @@ describe("stub", function () { assert(callback.calledOn(this.fakeContext)); }); - it("calls argument at specified index with undefined context", function () { + it("calls argument at specified index with undefined context", function() { this.stub.callsArgOn(2, undefined); var callback = createStub.create(); @@ -923,7 +973,7 @@ describe("stub", function () { assert(callback.calledOn(undefined)); }); - it("calls argument at specified index with number context", function () { + it("calls argument at specified index with number context", function() { this.stub.callsArgOn(2, 5); var callback = createStub.create(); @@ -933,37 +983,46 @@ describe("stub", function () { assert(callback.calledOn(5)); }); - it("returns stub", function () { + it("returns stub", function() { var stub = this.stub.callsArgOn(2, this.fakeContext); assert.isFunction(stub); }); - it("throws if argument at specified index is not callable", function () { + it("throws if argument at specified index is not callable", function() { this.stub.callsArgOn(0, this.fakeContext); - assert.exception(function () { - this.stub(1); - }, {name: "TypeError"}); + assert.exception( + function() { + this.stub(1); + }, + { name: "TypeError" } + ); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArgOn(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArgOn(); + }, + { name: "TypeError" } + ); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArgOn(this.fakeContext, 2); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArgOn(this.fakeContext, 2); + }, + { name: "TypeError" } + ); }); - it("returns result of invocant", function () { + it("returns result of invocant", function() { var stub = this.stub.callsArgOn(0, this.fakeContext); var callback = createStub().returns("return value"); @@ -973,13 +1032,13 @@ describe("stub", function () { }); }); - describe(".callsArgOnWith", function () { - beforeEach(function () { + describe(".callsArgOnWith", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("calls argument at specified index with provided args", function () { + it("calls argument at specified index with provided args", function() { var object = {}; this.stub.callsArgOnWith(1, this.fakeContext, object); var callback = createStub.create(); @@ -990,7 +1049,7 @@ describe("stub", function () { assert(callback.calledOn(this.fakeContext)); }); - it("calls argument at specified index with provided args and undefined context", function () { + it("calls argument at specified index with provided args and undefined context", function() { var object = {}; this.stub.callsArgOnWith(1, undefined, object); var callback = createStub.create(); @@ -1001,7 +1060,7 @@ describe("stub", function () { assert(callback.calledOn(undefined)); }); - it("calls argument at specified index with provided args and number context", function () { + it("calls argument at specified index with provided args and number context", function() { var object = {}; this.stub.callsArgOnWith(1, 5, object); var callback = createStub.create(); @@ -1012,7 +1071,7 @@ describe("stub", function () { assert(callback.calledOn(5)); }); - it("calls argument at specified index with provided args with undefined context", function () { + it("calls argument at specified index with provided args with undefined context", function() { var object = {}; this.stub.callsArgOnWith(1, undefined, object); var callback = createStub.create(); @@ -1023,7 +1082,7 @@ describe("stub", function () { assert(callback.calledOn(undefined)); }); - it("calls argument at specified index with provided args with number context", function () { + it("calls argument at specified index with provided args with number context", function() { var object = {}; this.stub.callsArgOnWith(1, 5, object); var callback = createStub.create(); @@ -1034,13 +1093,13 @@ describe("stub", function () { assert(callback.calledOn(5)); }); - it("returns function", function () { + it("returns function", function() { var stub = this.stub.callsArgOnWith(2, this.fakeContext, 3); assert.isFunction(stub); }); - it("calls callback without args", function () { + it("calls callback without args", function() { this.stub.callsArgOnWith(1, this.fakeContext); var callback = createStub.create(); @@ -1050,7 +1109,7 @@ describe("stub", function () { assert(callback.calledOn(this.fakeContext)); }); - it("calls callback with multiple args", function () { + it("calls callback with multiple args", function() { var object = {}; var array = []; this.stub.callsArgOnWith(1, this.fakeContext, object, array); @@ -1062,23 +1121,29 @@ describe("stub", function () { assert(callback.calledOn(this.fakeContext)); }); - it("throws if no index is specified", function () { + it("throws if no index is specified", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArgOnWith(); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArgOnWith(); + }, + { name: "TypeError" } + ); }); - it("throws if index is not number", function () { + it("throws if index is not number", function() { var stub = this.stub; - assert.exception(function () { - stub.callsArgOnWith({}); - }, {name: "TypeError"}); + assert.exception( + function() { + stub.callsArgOnWith({}); + }, + { name: "TypeError" } + ); }); - it("returns result of invocant", function () { + it("returns result of invocant", function() { var object = {}; var stub = this.stub.callsArgOnWith(0, this.fakeContext, object); var callback = createStub().returns("return value"); @@ -1089,13 +1154,15 @@ describe("stub", function () { }); }); - describe(".callsFake", function () { - beforeEach(function () { - this.method = function () { throw new Error("Should be stubbed"); }; - this.object = {method: this.method}; + describe(".callsFake", function() { + beforeEach(function() { + this.method = function() { + throw new Error("Should be stubbed"); + }; + this.object = { method: this.method }; }); - it("uses provided function as stub", function () { + it("uses provided function as stub", function() { var fakeFn = createStub.create(); this.stub = createStub(this.object, "method"); @@ -1106,7 +1173,7 @@ describe("stub", function () { assert(fakeFn.calledOn(this.object)); }); - it("is overwritten by subsequent stub behavior", function () { + it("is overwritten by subsequent stub behavior", function() { var fakeFn = createStub.create(); this.stub = createStub(this.object, "method"); @@ -1118,34 +1185,40 @@ describe("stub", function () { }); }); - describe(".objectMethod", function () { - beforeEach(function () { - this.method = function () { return; }; + describe(".objectMethod", function() { + beforeEach(function() { + this.method = function() { + return; + }; this.object = { method: this.method }; }); - afterEach(function () { + afterEach(function() { if (global.console.info.restore) { global.console.info.restore(); } }); - it("throws when third argument is provided", function () { + it("throws when third argument is provided", function() { var object = this.object; - assert.exception(function () { - createStub(object, "method", 1); - }, {message: "stub(obj, 'meth', fn) has been removed, see documentation"}, {name: "TypeError"}); + assert.exception( + function() { + createStub(object, "method", 1); + }, + { message: "stub(obj, 'meth', fn) has been removed, see documentation" }, + { name: "TypeError" } + ); }); - it("stubbed method should be proper stub", function () { + it("stubbed method should be proper stub", function() { var stub = createStub(this.object, "method"); assert.isFunction(stub.returns); assert.isFunction(stub.throws); }); - it("stub should be spy", function () { + it("stub should be spy", function() { var stub = createStub(this.object, "method"); this.object.method(); @@ -1153,7 +1226,7 @@ describe("stub", function () { assert(stub.calledOn(this.object)); }); - it("stub should affect spy", function () { + it("stub should affect spy", function() { var stub = createStub(this.object, "method"); stub.throws("TypeError"); @@ -1162,9 +1235,9 @@ describe("stub", function () { assert(stub.threw("TypeError")); }); - it("handles threw properly for lazily instantiated Errors", function () { + it("handles threw properly for lazily instantiated Errors", function() { var stub = createStub(this.object, "method"); - stub.throws(function () { + stub.throws(function() { return new TypeError(); }); @@ -1173,36 +1246,48 @@ describe("stub", function () { assert(stub.threw("TypeError")); }); - it("returns standalone stub without arguments", function () { + it("returns standalone stub without arguments", function() { var stub = createStub(); assert.isFunction(stub); assert.isFalse(stub.called); }); - it("successfully stubs falsey properties", function () { - var obj = { 0: function () { return; } }; + it("successfully stubs falsey properties", function() { + var obj = { + 0: function() { + return; + } + }; - createStub(obj, 0).callsFake(function () { + createStub(obj, 0).callsFake(function() { return "stubbed value"; }); assert.equals(obj[0](), "stubbed value"); }); - it("does not stub function object", function () { - assert.exception(function () { - createStub(function () { return; }); + it("does not stub function object", function() { + assert.exception(function() { + createStub(function() { + return; + }); }); }); }); - describe("everything", function () { - it("stubs all methods of object without property", function () { + describe("everything", function() { + it("stubs all methods of object without property", function() { var obj = { - func1: function () { return; }, - func2: function () { return; }, - func3: function () { return; } + func1: function() { + return; + }, + func2: function() { + return; + }, + func3: function() { + return; + } }; createStub(obj); @@ -1212,9 +1297,13 @@ describe("stub", function () { assert.isFunction(obj.func3.restore); }); - it("stubs prototype methods", function () { - function Obj() { return; } - Obj.prototype.func1 = function () { return; }; + it("stubs prototype methods", function() { + function Obj() { + return; + } + Obj.prototype.func1 = function() { + return; + }; var obj = new Obj(); createStub(obj); @@ -1222,27 +1311,33 @@ describe("stub", function () { assert.isFunction(obj.func1.restore); }); - it("returns object", function () { + it("returns object", function() { var object = {}; assert.same(createStub(object), object); }); - it("only stubs functions", function () { + it("only stubs functions", function() { var object = { foo: "bar" }; createStub(object); assert.equals(object.foo, "bar"); }); - it("handles non-enumerable properties", function () { + it("handles non-enumerable properties", function() { var obj = { - func1: function () { return; }, - func2: function () { return; } + func1: function() { + return; + }, + func2: function() { + return; + } }; Object.defineProperty(obj, "func3", { - value: function () { return; }, + value: function() { + return; + }, writable: true, configurable: true }); @@ -1254,10 +1349,14 @@ describe("stub", function () { assert.isFunction(obj.func3.restore); }); - it("handles non-enumerable properties on prototypes", function () { - function Obj() { return; } + it("handles non-enumerable properties on prototypes", function() { + function Obj() { + return; + } Object.defineProperty(Obj.prototype, "func1", { - value: function () { return; }, + value: function() { + return; + }, writable: true, configurable: true }); @@ -1269,7 +1368,7 @@ describe("stub", function () { assert.isFunction(obj.func1.restore); }); - it("does not stub non-enumerable properties from Object.prototype", function () { + it("does not stub non-enumerable properties from Object.prototype", function() { var obj = {}; createStub(obj); @@ -1279,19 +1378,23 @@ describe("stub", function () { refute.isFunction(obj.propertyIsEnumerable.restore); }); - it("does not fail on overrides", function () { + it("does not fail on overrides", function() { var parent = { - func: function () { return; } + func: function() { + return; + } }; var child = Object.create(parent); - child.func = function () { return; }; + child.func = function() { + return; + }; - refute.exception(function () { + refute.exception(function() { createStub(child); }); }); - it("does not call getter during restore", function () { + it("does not call getter during restore", function() { var obj = { get prop() { fail("should not call getter"); @@ -1299,7 +1402,7 @@ describe("stub", function () { } }; - var stub = createStub(obj, "prop").get(function () { + var stub = createStub(obj, "prop").get(function() { return 43; }); assert.equals(obj.prop, 43); @@ -1307,10 +1410,10 @@ describe("stub", function () { stub.restore(); }); - it("throws if stubbing non-existent property", function () { + it("throws if stubbing non-existent property", function() { var myObj = {}; - assert.exception(function () { + assert.exception(function() { createStub(myObj, "ouch"); }); @@ -1318,21 +1421,25 @@ describe("stub", function () { }); }); - describe("stubbed function", function () { - it("has toString method", function () { - var obj = { meth: function () { return; } }; + describe("stubbed function", function() { + it("has toString method", function() { + var obj = { + meth: function() { + return; + } + }; createStub(obj, "meth"); assert.equals(obj.meth.toString(), "meth"); }); - it("toString should say 'stub' when unable to infer name", function () { + it("toString should say 'stub' when unable to infer name", function() { var stub = createStub(); assert.equals(stub.toString(), "stub"); }); - it("toString should prefer property name if possible", function () { + it("toString should prefer property name if possible", function() { var obj = {}; obj.meth = createStub(); obj.meth(); @@ -1341,8 +1448,8 @@ describe("stub", function () { }); }); - describe(".yields", function () { - it("invokes only argument as callback", function () { + describe(".yields", function() { + it("invokes only argument as callback", function() { var stub = createStub().yields(); var spy = createSpy(); stub(spy); @@ -1351,7 +1458,7 @@ describe("stub", function () { assert.equals(spy.args[0].length, 0); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var stub = createStub().yields(); assert.exception(stub, { @@ -1359,22 +1466,25 @@ describe("stub", function () { }); }); - it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () { return; } }; + it("includes stub name and actual arguments in error", function() { + var myObj = { + somethingAwesome: function() { + return; + } + }; var stub = createStub(myObj, "somethingAwesome").yields(); assert.exception( - function () { + function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield, but no callback " + - "was passed. Received [23, 42]" + message: "somethingAwesome expected to yield, but no callback " + "was passed. Received [23, 42]" } ); }); - it("invokes last argument as callback", function () { + it("invokes last argument as callback", function() { var stub = createStub().yields(); var spy = createSpy(); stub(24, {}, spy); @@ -1383,7 +1493,7 @@ describe("stub", function () { assert.equals(spy.args[0].length, 0); }); - it("invokes first of two callbacks", function () { + it("invokes first of two callbacks", function() { var stub = createStub().yields(); var spy = createSpy(); var spy2 = createSpy(); @@ -1393,7 +1503,7 @@ describe("stub", function () { assert(!spy2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var stub = createStub().yields(obj, "Crazy"); var spy = createSpy(); @@ -1402,53 +1512,61 @@ describe("stub", function () { assert(spy.calledWith(obj, "Crazy")); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { var obj = { id: 42 }; var stub = createStub().yields(obj, "Crazy"); var callback = createStub().throws(); - assert.exception(function () { + assert.exception(function() { stub(callback); }); }); - it("throws takes precedent over yielded return value", function () { - var stub = createStub().throws().yields(); + it("throws takes precedent over yielded return value", function() { + var stub = createStub() + .throws() + .yields(); var callback = createStub().returns("return value"); - assert.exception(function () { + assert.exception(function() { stub(callback); }); assert(callback.calledOnce); }); - it("returns takes precedent over yielded return value", function () { + it("returns takes precedent over yielded return value", function() { var obj = {}; - var stub = createStub().returns(obj).yields(); + var stub = createStub() + .returns(obj) + .yields(); var callback = createStub().returns("return value"); assert.same(stub(callback), obj); assert(callback.calledOnce); }); - it("returnsArg takes precedent over yielded return value", function () { - var stub = createStub().returnsArg(0).yields(); + it("returnsArg takes precedent over yielded return value", function() { + var stub = createStub() + .returnsArg(0) + .yields(); var callback = createStub().returns("return value"); assert.same(stub(callback), callback); assert(callback.calledOnce); }); - it("returnsThis takes precedent over yielded return value", function () { + it("returnsThis takes precedent over yielded return value", function() { var obj = {}; - var stub = createStub().returnsThis().yields(); + var stub = createStub() + .returnsThis() + .yields(); var callback = createStub().returns("return value"); assert.same(stub.call(obj, callback), obj); assert(callback.calledOnce); }); - it("returns the result of the yielded callback", function () { + it("returns the result of the yielded callback", function() { var stub = createStub().yields(); var callback = createStub().returns("return value"); @@ -1457,8 +1575,8 @@ describe("stub", function () { }); }); - describe(".yieldsRight", function () { - it("invokes only argument as callback", function () { + describe(".yieldsRight", function() { + it("invokes only argument as callback", function() { var stub = createStub().yieldsRight(); var spy = createSpy(); stub(spy); @@ -1467,7 +1585,7 @@ describe("stub", function () { assert.equals(spy.args[0].length, 0); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { var stub = createStub().yieldsRight(); assert.exception(stub, { @@ -1475,22 +1593,25 @@ describe("stub", function () { }); }); - it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () { return; } }; + it("includes stub name and actual arguments in error", function() { + var myObj = { + somethingAwesome: function() { + return; + } + }; var stub = createStub(myObj, "somethingAwesome").yieldsRight(); assert.exception( - function () { + function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield, but no callback " + - "was passed. Received [23, 42]" + message: "somethingAwesome expected to yield, but no callback " + "was passed. Received [23, 42]" } ); }); - it("invokes last argument as callback", function () { + it("invokes last argument as callback", function() { var stub = createStub().yieldsRight(); var spy = createSpy(); stub(24, {}, spy); @@ -1499,7 +1620,7 @@ describe("stub", function () { assert.equals(spy.args[0].length, 0); }); - it("invokes the last of two callbacks", function () { + it("invokes the last of two callbacks", function() { var stub = createStub().yieldsRight(); var spy = createSpy(); var spy2 = createSpy(); @@ -1509,7 +1630,7 @@ describe("stub", function () { assert(spy2.calledOnce); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var stub = createStub().yieldsRight(obj, "Crazy"); var spy = createSpy(); @@ -1518,53 +1639,61 @@ describe("stub", function () { assert(spy.calledWith(obj, "Crazy")); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { var obj = { id: 42 }; var stub = createStub().yieldsRight(obj, "Crazy"); var callback = createStub().throws(); - assert.exception(function () { + assert.exception(function() { stub(callback); }); }); - it("throws takes precedent over yielded return value", function () { - var stub = createStub().yieldsRight().throws(); + it("throws takes precedent over yielded return value", function() { + var stub = createStub() + .yieldsRight() + .throws(); var callback = createStub().returns("return value"); - assert.exception(function () { + assert.exception(function() { stub(callback); }); assert(callback.calledOnce); }); - it("returns takes precedent over yielded return value", function () { + it("returns takes precedent over yielded return value", function() { var obj = {}; - var stub = createStub().returns(obj).yieldsRight(); + var stub = createStub() + .returns(obj) + .yieldsRight(); var callback = createStub().returns("return value"); assert.same(stub(callback), obj); assert(callback.calledOnce); }); - it("returnsArg takes precedent over yielded return value", function () { - var stub = createStub().returnsArg(0).yieldsRight(); + it("returnsArg takes precedent over yielded return value", function() { + var stub = createStub() + .returnsArg(0) + .yieldsRight(); var callback = createStub().returns("return value"); assert.same(stub(callback), callback); assert(callback.calledOnce); }); - it("returnsThis takes precedent over yielded return value", function () { + it("returnsThis takes precedent over yielded return value", function() { var obj = {}; - var stub = createStub().returnsThis().yieldsRight(); + var stub = createStub() + .returnsThis() + .yieldsRight(); var callback = createStub().returns("return value"); assert.same(stub.call(obj, callback), obj); assert(callback.calledOnce); }); - it("returns the result of the yielded callback", function () { + it("returns the result of the yielded callback", function() { var stub = createStub().yields(); var callback = createStub().returns("return value"); @@ -1573,13 +1702,13 @@ describe("stub", function () { }); }); - describe(".yieldsOn", function () { - beforeEach(function () { + describe(".yieldsOn", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("invokes only argument as callback", function () { + it("invokes only argument as callback", function() { var spy = createSpy(); this.stub.yieldsOn(this.fakeContext); @@ -1590,13 +1719,16 @@ describe("stub", function () { assert.equals(spy.args[0].length, 0); }); - it("throws if no context is specified", function () { - assert.exception(function () { - this.stub.yieldsOn(); - }, {name: "TypeError"}); + it("throws if no context is specified", function() { + assert.exception( + function() { + this.stub.yieldsOn(); + }, + { name: "TypeError" } + ); }); - it("throws understandable error if no callback is passed", function () { + it("throws understandable error if no callback is passed", function() { this.stub.yieldsOn(this.fakeContext); assert.exception(this.stub, { @@ -1604,22 +1736,25 @@ describe("stub", function () { }); }); - it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () { return; } }; + it("includes stub name and actual arguments in error", function() { + var myObj = { + somethingAwesome: function() { + return; + } + }; var stub = createStub(myObj, "somethingAwesome").yieldsOn(this.fakeContext); assert.exception( - function () { + function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield, but no callback " + - "was passed. Received [23, 42]" + message: "somethingAwesome expected to yield, but no callback " + "was passed. Received [23, 42]" } ); }); - it("invokes last argument as callback", function () { + it("invokes last argument as callback", function() { var spy = createSpy(); this.stub.yieldsOn(this.fakeContext); @@ -1630,7 +1765,7 @@ describe("stub", function () { assert.equals(spy.args[0].length, 0); }); - it("invokes first of two callbacks", function () { + it("invokes first of two callbacks", function() { var spy = createSpy(); var spy2 = createSpy(); @@ -1642,7 +1777,7 @@ describe("stub", function () { assert(!spy2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var spy = createSpy(); @@ -1653,28 +1788,28 @@ describe("stub", function () { assert(spy.calledOn(this.fakeContext)); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { var obj = { id: 42 }; var callback = createStub().throws(); this.stub.yieldsOn(this.fakeContext, obj, "Crazy"); - assert.exception(function () { + assert.exception(function() { this.stub(callback); }); }); - it("throws takes precedent over yielded return value", function () { + it("throws takes precedent over yielded return value", function() { var stub = this.stub.throws().yieldsOn(this.fakeContext); var callback = createStub().returns("return value"); - assert.exception(function () { + assert.exception(function() { stub(callback); }); assert(callback.calledOnce); }); - it("returns takes precedent over yielded return value", function () { + it("returns takes precedent over yielded return value", function() { var obj = {}; var stub = this.stub.returns(obj).yieldsOn(this.fakeContext); var callback = createStub().returns("return value"); @@ -1683,7 +1818,7 @@ describe("stub", function () { assert(callback.calledOnce); }); - it("returnsArg takes precedent over yielded return value", function () { + it("returnsArg takes precedent over yielded return value", function() { var stub = this.stub.returnsArg(0).yieldsOn(); var callback = createStub().returns("return value"); @@ -1691,7 +1826,7 @@ describe("stub", function () { assert(callback.calledOnce); }); - it("returnsThis takes precedent over yielded return value", function () { + it("returnsThis takes precedent over yielded return value", function() { var obj = {}; var stub = this.stub.returnsThis().yieldsOn(this.fakeContext); var callback = createStub().returns("return value"); @@ -1700,7 +1835,7 @@ describe("stub", function () { assert(callback.calledOnce); }); - it("returns the result of the yielded callback", function () { + it("returns the result of the yielded callback", function() { var stub = this.stub.yieldsOn(this.fakeContext); var callback = createStub().returns("return value"); @@ -1709,8 +1844,8 @@ describe("stub", function () { }); }); - describe(".yieldsTo", function () { - it("yields to property of object argument", function () { + describe(".yieldsTo", function() { + it("yields to property of object argument", function() { var stub = createStub().yieldsTo("success"); var callback = createSpy(); @@ -1720,45 +1855,48 @@ describe("stub", function () { assert.equals(callback.args[0].length, 0); }); - it("throws understandable error if no object with callback is passed", function () { + it("throws understandable error if no object with callback is passed", function() { var stub = createStub().yieldsTo("success"); assert.exception(stub, { - message: "stub expected to yield to 'success', but no object " + - "with such a property was passed." + message: "stub expected to yield to 'success', but no object " + "with such a property was passed." }); }); - it("throws understandable error if failing to yield callback by symbol", function () { + it("throws understandable error if failing to yield callback by symbol", function() { if (typeof Symbol === "function") { var symbol = Symbol(); var stub = createStub().yieldsTo(symbol); assert.exception(stub, { - message: "stub expected to yield to 'Symbol()', but no object with " + - "such a property was passed." + message: "stub expected to yield to 'Symbol()', but no object with " + "such a property was passed." }); } }); - it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () { return; } }; + it("includes stub name and actual arguments in error", function() { + var myObj = { + somethingAwesome: function() { + return; + } + }; var stub = createStub(myObj, "somethingAwesome").yieldsTo("success"); assert.exception( - function () { + function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield to 'success', but " + - "no object with such a property was passed. " + - "Received [23, 42]" + message: + "somethingAwesome expected to yield to 'success', but " + + "no object with such a property was passed. " + + "Received [23, 42]" } ); }); - it("invokes property on last argument as callback", function () { + it("invokes property on last argument as callback", function() { var stub = createStub().yieldsTo("success"); var callback = createSpy(); stub(24, {}, { success: callback }); @@ -1767,7 +1905,7 @@ describe("stub", function () { assert.equals(callback.args[0].length, 0); }); - it("invokes first of two possible callbacks", function () { + it("invokes first of two possible callbacks", function() { var stub = createStub().yieldsTo("error"); var callback = createSpy(); var callback2 = createSpy(); @@ -1777,7 +1915,7 @@ describe("stub", function () { assert(!callback2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var stub = createStub().yieldsTo("success", obj, "Crazy"); var callback = createSpy(); @@ -1786,68 +1924,76 @@ describe("stub", function () { assert(callback.calledWith(obj, "Crazy")); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { var obj = { id: 42 }; var stub = createStub().yieldsTo("error", obj, "Crazy"); var callback = createStub().throws(); - assert.exception(function () { + assert.exception(function() { stub({ error: callback }); }); }); - it("throws takes precedent over yielded return value", function () { - var stub = createStub().throws().yieldsTo("success"); + it("throws takes precedent over yielded return value", function() { + var stub = createStub() + .throws() + .yieldsTo("success"); var callback = createStub().returns("return value"); - assert.exception(function () { - stub({success: callback}); + assert.exception(function() { + stub({ success: callback }); }); assert(callback.calledOnce); }); - it("returns takes precedent over yielded return value", function () { + it("returns takes precedent over yielded return value", function() { var obj = {}; - var stub = createStub().returns(obj).yieldsTo("success"); + var stub = createStub() + .returns(obj) + .yieldsTo("success"); var callback = createStub().returns("return value"); - assert.same(stub({success: callback}), obj); + assert.same(stub({ success: callback }), obj); assert(callback.calledOnce); }); - it("returnsArg takes precedent over yielded return value", function () { - var stub = createStub().returnsArg(0).yieldsTo("success"); + it("returnsArg takes precedent over yielded return value", function() { + var stub = createStub() + .returnsArg(0) + .yieldsTo("success"); var callback = createStub().returns("return value"); - assert.equals(stub({success: callback}), {success: callback}); + assert.equals(stub({ success: callback }), { success: callback }); assert(callback.calledOnce); }); - it("returnsThis takes precedent over yielded return value", function () { + it("returnsThis takes precedent over yielded return value", function() { var obj = {}; - var stub = createStub().returnsThis().yieldsTo("success"); + var stub = createStub() + .returnsThis() + .yieldsTo("success"); var callback = createStub().returns("return value"); - assert.same(stub.call(obj, {success: callback}), obj); + assert.same(stub.call(obj, { success: callback }), obj); assert(callback.calledOnce); }); - it("returns the result of the yielded callback", function () { + it("returns the result of the yielded callback", function() { var stub = createStub().yieldsTo("success"); var callback = createStub().returns("return value"); - assert.same(stub({success: callback}), "return value"); + assert.same(stub({ success: callback }), "return value"); assert(callback.calledOnce); }); }); - describe(".yieldsToOn", function () { - beforeEach(function () { + describe(".yieldsToOn", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("yields to property of object argument", function () { + it("yields to property of object argument", function() { this.stub.yieldsToOn("success", this.fakeContext); var callback = createSpy(); @@ -1858,7 +2004,7 @@ describe("stub", function () { assert.equals(callback.args[0].length, 0); }); - it("yields to property of object argument with undefined context", function () { + it("yields to property of object argument with undefined context", function() { this.stub.yieldsToOn("success", undefined); var callback = createSpy(); @@ -1869,7 +2015,7 @@ describe("stub", function () { assert.equals(callback.args[0].length, 0); }); - it("yields to property of object argument with number context", function () { + it("yields to property of object argument with number context", function() { this.stub.yieldsToOn("success", 5); var callback = createSpy(); @@ -1880,32 +2026,36 @@ describe("stub", function () { assert.equals(callback.args[0].length, 0); }); - it("throws understandable error if no object with callback is passed", function () { + it("throws understandable error if no object with callback is passed", function() { this.stub.yieldsToOn("success", this.fakeContext); assert.exception(this.stub, { - message: "stub expected to yield to 'success', but no object " + - "with such a property was passed." + message: "stub expected to yield to 'success', but no object " + "with such a property was passed." }); }); - it("includes stub name and actual arguments in error", function () { - var myObj = { somethingAwesome: function () { return; } }; + it("includes stub name and actual arguments in error", function() { + var myObj = { + somethingAwesome: function() { + return; + } + }; var stub = createStub(myObj, "somethingAwesome").yieldsToOn("success", this.fakeContext); assert.exception( - function () { + function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield to 'success', but " + - "no object with such a property was passed. " + - "Received [23, 42]" + message: + "somethingAwesome expected to yield to 'success', but " + + "no object with such a property was passed. " + + "Received [23, 42]" } ); }); - it("invokes property on last argument as callback", function () { + it("invokes property on last argument as callback", function() { var callback = createSpy(); this.stub.yieldsToOn("success", this.fakeContext); @@ -1916,7 +2066,7 @@ describe("stub", function () { assert.equals(callback.args[0].length, 0); }); - it("invokes first of two possible callbacks", function () { + it("invokes first of two possible callbacks", function() { var callback = createSpy(); var callback2 = createSpy(); @@ -1928,7 +2078,7 @@ describe("stub", function () { assert(!callback2.called); }); - it("invokes callback with arguments", function () { + it("invokes callback with arguments", function() { var obj = { id: 42 }; var callback = createSpy(); @@ -1939,70 +2089,70 @@ describe("stub", function () { assert(callback.calledWith(obj, "Crazy")); }); - it("throws if callback throws", function () { + it("throws if callback throws", function() { var obj = { id: 42 }; var callback = createStub().throws(); this.stub.yieldsToOn("error", this.fakeContext, obj, "Crazy"); - assert.exception(function () { + assert.exception(function() { this.stub({ error: callback }); }); }); - it("throws takes precedent over yielded return value", function () { + it("throws takes precedent over yielded return value", function() { var stub = this.stub.throws().yieldsToOn("success", this.fakeContext); var callback = createStub().returns("return value"); - assert.exception(function () { - stub({success: callback}); + assert.exception(function() { + stub({ success: callback }); }); assert(callback.calledOnce); }); - it("returns takes precedent over yielded return value", function () { + it("returns takes precedent over yielded return value", function() { var obj = {}; var stub = this.stub.returns(obj).yieldsToOn("success", this.fakeContext); var callback = createStub().returns("return value"); - assert.same(stub({success: callback}), obj); + assert.same(stub({ success: callback }), obj); assert(callback.calledOnce); }); - it("returnsArg takes precedent over yielded return value", function () { + it("returnsArg takes precedent over yielded return value", function() { var stub = this.stub.returnsArg(0).yieldsToOn("success", this.fakeContext); var callback = createStub().returns("return value"); - assert.equals(stub({success: callback}), {success: callback}); + assert.equals(stub({ success: callback }), { success: callback }); assert(callback.calledOnce); }); - it("returnsThis takes precedent over yielded return value", function () { + it("returnsThis takes precedent over yielded return value", function() { var obj = {}; var stub = this.stub.returnsThis().yieldsToOn("success", this.fakeContext); var callback = createStub().returns("return value"); - assert.same(stub.call(obj, {success: callback}), obj); + assert.same(stub.call(obj, { success: callback }), obj); assert(callback.calledOnce); }); - it("returns the result of the yielded callback", function () { + it("returns the result of the yielded callback", function() { var stub = this.stub.yieldsToOn("success", this.fakeContext); var callback = createStub().returns("return value"); - assert.same(stub({success: callback}), "return value"); + assert.same(stub({ success: callback }), "return value"); assert(callback.calledOnce); }); }); - describe(".withArgs", function () { - it("defines withArgs method", function () { + describe(".withArgs", function() { + it("defines withArgs method", function() { var stub = createStub(); assert.isFunction(stub.withArgs); }); - it("creates filtered stub", function () { + it("creates filtered stub", function() { var stub = createStub(); var other = stub.withArgs(23); @@ -2011,7 +2161,7 @@ describe("stub", function () { assert.isFunction(other.returns); }); - it("filters return values based on arguments", function () { + it("filters return values based on arguments", function() { var stub = createStub().returns(23); stub.withArgs(42).returns(99); @@ -2019,17 +2169,17 @@ describe("stub", function () { assert.equals(stub(42), 99); }); - it("filters exceptions based on arguments", function () { + it("filters exceptions based on arguments", function() { var stub = createStub().returns(23); stub.withArgs(42).throws(); refute.exception(stub); - assert.exception(function () { + assert.exception(function() { stub(42); }); }); - it("ensure stub recognizes sinonMatch fuzzy arguments", function () { + it("ensure stub recognizes sinonMatch fuzzy arguments", function() { var stub = createStub().returns(23); stub.withArgs(sinonMatch({ foo: "bar" })).returns(99); @@ -2037,7 +2187,7 @@ describe("stub", function () { assert.equals(stub({ foo: "bar", bar: "foo" }), 99); }); - it("ensure stub uses last matching arguments", function () { + it("ensure stub uses last matching arguments", function() { var unmatchedValue = "d3ada6a0-8dac-4136-956d-033b5f23eadf"; var firstMatchedValue = "68128619-a639-4b32-a4a0-6519165bf301"; var secondMatchedValue = "4ac2dc8f-3f3f-4648-9838-a2825fd94c9a"; @@ -2052,7 +2202,7 @@ describe("stub", function () { assert.equals(stub(expectedArgument), secondMatchedValue); }); - it("ensure stub uses last matching sinonMatch arguments", function () { + it("ensure stub uses last matching sinonMatch arguments", function() { var unmatchedValue = "0aa66a7d-3c50-49ef-8365-bdcab637b2dd"; var firstMatchedValue = "1ab2c601-7602-4658-9377-3346f6814caa"; var secondMatchedValue = "e2e31518-c4c4-4012-a61f-31942f603ffa"; @@ -2067,12 +2217,12 @@ describe("stub", function () { }); }); - describe(".callsArgAsync", function () { - beforeEach(function () { + describe(".callsArgAsync", function() { + beforeEach(function() { this.stub = createStub.create(); }); - it("asynchronously calls argument at specified index", function (done) { + it("asynchronously calls argument at specified index", function(done) { this.stub.callsArgAsync(2); var callback = createSpy(done); @@ -2082,17 +2232,17 @@ describe("stub", function () { }); }); - describe(".callsArgWithAsync", function () { - beforeEach(function () { + describe(".callsArgWithAsync", function() { + beforeEach(function() { this.stub = createStub.create(); }); - it("asynchronously calls callback at specified index with multiple args", function (done) { + it("asynchronously calls callback at specified index with multiple args", function(done) { var object = {}; var array = []; this.stub.callsArgWithAsync(1, object, array); - var callback = createSpy(function () { + var callback = createSpy(function() { assert(callback.calledWith(object, array)); done(); }); @@ -2103,19 +2253,19 @@ describe("stub", function () { }); }); - describe(".callsArgOnAsync", function () { - beforeEach(function () { + describe(".callsArgOnAsync", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("asynchronously calls argument at specified index with specified context", function (done) { + it("asynchronously calls argument at specified index with specified context", function(done) { var context = this.fakeContext; this.stub.callsArgOnAsync(2, context); - var callback = createSpy(function () { + var callback = createSpy(function() { assert(callback.calledOn(context)); done(); }); @@ -2126,18 +2276,18 @@ describe("stub", function () { }); }); - describe(".callsArgOnWithAsync", function () { - beforeEach(function () { + describe(".callsArgOnWithAsync", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("asynchronously calls argument at specified index with provided context and args", function (done) { + it("asynchronously calls argument at specified index with provided context and args", function(done) { var object = {}; var context = this.fakeContext; this.stub.callsArgOnWithAsync(1, context, object); - var callback = createSpy(function () { + var callback = createSpy(function() { assert(callback.calledOn(context)); assert(callback.calledWith(object)); done(); @@ -2149,8 +2299,8 @@ describe("stub", function () { }); }); - describe(".yieldsAsync", function () { - it("asynchronously invokes only argument as callback", function (done) { + describe(".yieldsAsync", function() { + it("asynchronously invokes only argument as callback", function(done) { var stub = createStub().yieldsAsync(); var spy = createSpy(done); @@ -2161,17 +2311,17 @@ describe("stub", function () { }); }); - describe(".yieldsOnAsync", function () { - beforeEach(function () { + describe(".yieldsOnAsync", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("asynchronously invokes only argument as callback with given context", function (done) { + it("asynchronously invokes only argument as callback with given context", function(done) { var context = this.fakeContext; this.stub.yieldsOnAsync(context); - var spy = createSpy(function () { + var spy = createSpy(function() { assert(spy.calledOnce); assert(spy.calledOn(context)); assert.equals(spy.args[0].length, 0); @@ -2184,11 +2334,11 @@ describe("stub", function () { }); }); - describe(".yieldsToAsync", function () { - it("asynchronously yields to property of object argument", function (done) { + describe(".yieldsToAsync", function() { + it("asynchronously yields to property of object argument", function(done) { var stub = createStub().yieldsToAsync("success"); - var callback = createSpy(function () { + var callback = createSpy(function() { assert(callback.calledOnce); assert.equals(callback.args[0].length, 0); done(); @@ -2200,17 +2350,17 @@ describe("stub", function () { }); }); - describe(".yieldsToOnAsync", function () { - beforeEach(function () { + describe(".yieldsToOnAsync", function() { + beforeEach(function() { this.stub = createStub.create(); this.fakeContext = { foo: "bar" }; }); - it("asynchronously yields to property of object argument with given context", function (done) { + it("asynchronously yields to property of object argument with given context", function(done) { var context = this.fakeContext; this.stub.yieldsToOnAsync("success", context); - var callback = createSpy(function () { + var callback = createSpy(function() { assert(callback.calledOnce); assert(callback.calledOn(context)); assert.equals(callback.args[0].length, 0); @@ -2222,11 +2372,13 @@ describe("stub", function () { }); }); - describe(".onCall", function () { - it("can be used with returns to produce sequence", function () { + describe(".onCall", function() { + it("can be used with returns to produce sequence", function() { var stub = createStub().returns(3); - stub.onFirstCall().returns(1) - .onCall(2).returns(2); + stub.onFirstCall() + .returns(1) + .onCall(2) + .returns(2); assert.same(stub(), 1); assert.same(stub(), 3); @@ -2234,7 +2386,7 @@ describe("stub", function () { assert.same(stub(), 3); }); - it("can be used with returnsArg to produce sequence", function () { + it("can be used with returnsArg to produce sequence", function() { var stub = createStub().returns("default"); stub.onSecondCall().returnsArg(0); @@ -2243,7 +2395,7 @@ describe("stub", function () { assert.same(stub(3), "default"); }); - it("can be used with returnsThis to produce sequence", function () { + it("can be used with returnsThis to produce sequence", function() { var instance = {}; instance.stub = createStub().returns("default"); instance.stub.onSecondCall().returnsThis(); @@ -2253,35 +2405,41 @@ describe("stub", function () { assert.same(instance.stub(), "default"); }); - it("can be used with throwsException to produce sequence", function () { + it("can be used with throwsException to produce sequence", function() { var stub = createStub(); var error = new Error(); stub.onSecondCall().throwsException(error); stub(); - assert.exception(stub, function (e) { + assert.exception(stub, function(e) { return e === error; }); }); - it("supports chained declaration of behavior", function () { + it("supports chained declaration of behavior", function() { var stub = createStub() - .onCall(0).returns(1) - .onCall(1).returns(2) - .onCall(2).returns(3); + .onCall(0) + .returns(1) + .onCall(1) + .returns(2) + .onCall(2) + .returns(3); assert.same(stub(), 1); assert.same(stub(), 2); assert.same(stub(), 3); }); - describe("in combination with withArgs", function () { - it("can produce a sequence for a fake", function () { + describe("in combination with withArgs", function() { + it("can produce a sequence for a fake", function() { var stub = createStub().returns(0); - stub.withArgs(5).returns(-1) - .onFirstCall().returns(1) - .onSecondCall().returns(2); + stub.withArgs(5) + .returns(-1) + .onFirstCall() + .returns(1) + .onSecondCall() + .returns(2); assert.same(stub(0), 0); assert.same(stub(5), 1); @@ -2290,18 +2448,21 @@ describe("stub", function () { assert.same(stub(5), -1); }); - it("falls back to stub default behaviour if fake does not have its own default behaviour", function () { + it("falls back to stub default behaviour if fake does not have its own default behaviour", function() { var stub = createStub().returns(0); stub.withArgs(5) - .onFirstCall().returns(1); + .onFirstCall() + .returns(1); assert.same(stub(5), 1); assert.same(stub(5), 0); }); - it("falls back to stub behaviour for call if fake does not have its own behaviour for call", function () { + it("falls back to stub behaviour for call if fake does not have its own behaviour for call", function() { var stub = createStub().returns(0); - stub.withArgs(5).onFirstCall().returns(1); + stub.withArgs(5) + .onFirstCall() + .returns(1); stub.onSecondCall().returns(2); assert.same(stub(5), 1); @@ -2309,27 +2470,34 @@ describe("stub", function () { assert.same(stub(4), 0); }); - it("defaults to undefined behaviour once no more calls have been defined", function () { + it("defaults to undefined behaviour once no more calls have been defined", function() { var stub = createStub(); - stub.withArgs(5).onFirstCall().returns(1) - .onSecondCall().returns(2); + stub.withArgs(5) + .onFirstCall() + .returns(1) + .onSecondCall() + .returns(2); assert.same(stub(5), 1); assert.same(stub(5), 2); refute.defined(stub(5)); }); - it("does not create undefined behaviour just by calling onCall", function () { + it("does not create undefined behaviour just by calling onCall", function() { var stub = createStub().returns(2); stub.onFirstCall(); assert.same(stub(6), 2); }); - it("works with fakes and reset", function () { + it("works with fakes and reset", function() { var stub = createStub(); - stub.withArgs(5).onFirstCall().returns(1); - stub.withArgs(5).onSecondCall().returns(2); + stub.withArgs(5) + .onFirstCall() + .returns(1); + stub.withArgs(5) + .onSecondCall() + .returns(2); assert.same(stub(5), 1); assert.same(stub(5), 2); @@ -2342,10 +2510,12 @@ describe("stub", function () { refute.defined(stub(5)); }); - it("throws an understandable error when trying to use withArgs on behavior", function () { + it("throws an understandable error when trying to use withArgs on behavior", function() { assert.exception( - function () { - createStub().onFirstCall().withArgs(1); + function() { + createStub() + .onFirstCall() + .withArgs(1); }, { message: /not supported/ @@ -2354,15 +2524,19 @@ describe("stub", function () { }); }); - it("can be used with yields* to produce a sequence", function () { + it("can be used with yields* to produce a sequence", function() { var context = { foo: "bar" }; var obj = { method1: createSpy(), method2: createSpy() }; var obj2 = { method2: createSpy() }; var stub = createStub().yieldsToOn("method2", context, 7, 8); - stub.onFirstCall().yields(1, 2) - .onSecondCall().yieldsOn(context, 3, 4) - .onThirdCall().yieldsTo("method1", 5, 6) - .onCall(3).yieldsToOn("method2", context, 7, 8); + stub.onFirstCall() + .yields(1, 2) + .onSecondCall() + .yieldsOn(context, 3, 4) + .onThirdCall() + .yieldsTo("method1", 5, 6) + .onCall(3) + .yieldsToOn("method2", context, 7, 8); var spy1 = createSpy(); var spy2 = createSpy(); @@ -2396,7 +2570,7 @@ describe("stub", function () { assert(obj2.method2.calledWithExactly(7, 8)); }); - it("can be used with callsArg* to produce a sequence", function () { + it("can be used with callsArg* to produce a sequence", function() { var spy1 = createSpy(); var spy2 = createSpy(); var spy3 = createSpy(); @@ -2406,10 +2580,14 @@ describe("stub", function () { var context = { foo: "bar" }; var stub = createStub().callsArgOnWith(3, context, "c", "d"); - stub.onFirstCall().callsArg(0) - .onSecondCall().callsArgWith(1, "a", "b") - .onThirdCall().callsArgOn(2, context) - .onCall(3).callsArgOnWith(3, context, "c", "d"); + stub.onFirstCall() + .callsArg(0) + .onSecondCall() + .callsArgWith(1, "a", "b") + .onThirdCall() + .callsArgOn(2, context) + .onCall(3) + .callsArgOnWith(3, context, "c", "d"); stub(spy1); stub(decoy, spy2); @@ -2440,11 +2618,14 @@ describe("stub", function () { assert(decoy.notCalled); }); - it("can be used with yields* and callsArg* in combination to produce a sequence", function () { + it("can be used with yields* and callsArg* in combination to produce a sequence", function() { var stub = createStub().yields(1, 2); - stub.onSecondCall().callsArg(1) - .onThirdCall().yieldsTo("method") - .onCall(3).callsArgWith(2, "a", "b"); + stub.onSecondCall() + .callsArg(1) + .onThirdCall() + .yieldsTo("method") + .onCall(3) + .callsArgWith(2, "a", "b"); var obj = { method: createSpy() }; var spy1 = createSpy(); @@ -2472,7 +2653,7 @@ describe("stub", function () { assert(decoy.notCalled); }); - it("should interact correctly with assertions (GH-231)", function () { + it("should interact correctly with assertions (GH-231)", function() { var stub = createStub(); var spy = createSpy(); @@ -2491,9 +2672,13 @@ describe("stub", function () { }); }); - describe(".reset", function () { - it("resets behavior", function () { - var obj = { a: function () { return; } }; + describe(".reset", function() { + it("resets behavior", function() { + var obj = { + a: function() { + return; + } + }; var spy = createSpy(); createStub(obj, "a").callsArg(1); @@ -2504,7 +2689,7 @@ describe("stub", function () { assert(spy.calledOnce); }); - it("resets call history", function () { + it("resets call history", function() { var stub = createStub(); stub(1); @@ -2516,8 +2701,8 @@ describe("stub", function () { }); }); - describe(".resetHistory", function () { - it("resets history", function () { + describe(".resetHistory", function() { + it("resets history", function() { var stub = createStub(); stub(1); @@ -2528,7 +2713,7 @@ describe("stub", function () { assert.equals(stub.getCall(0).args[0], 2); }); - it("doesn't reset behavior defined using withArgs", function () { + it("doesn't reset behavior defined using withArgs", function() { var stub = createStub(); stub.withArgs("test").returns(10); @@ -2537,7 +2722,7 @@ describe("stub", function () { assert.equals(stub("test"), 10); }); - it("doesn't reset behavior", function () { + it("doesn't reset behavior", function() { var stub = createStub(); stub.returns(10); @@ -2547,8 +2732,8 @@ describe("stub", function () { }); }); - describe(".resetBehavior", function () { - it("clears yields* and callsArg* sequence", function () { + describe(".resetBehavior", function() { + it("clears yields* and callsArg* sequence", function() { var stub = createStub().yields(1); stub.onFirstCall().callsArg(1); stub.resetBehavior(); @@ -2563,7 +2748,7 @@ describe("stub", function () { assert(spyWanted.calledWithExactly(3)); }); - it("cleans 'returns' behavior", function () { + it("cleans 'returns' behavior", function() { var stub = createStub().returns(1); stub.resetBehavior(); @@ -2571,7 +2756,7 @@ describe("stub", function () { refute.defined(stub()); }); - it("cleans behavior of fakes returned by withArgs", function () { + it("cleans behavior of fakes returned by withArgs", function() { var stub = createStub(); stub.withArgs("lolz").returns(2); @@ -2580,7 +2765,7 @@ describe("stub", function () { refute.defined(stub("lolz")); }); - it("does not clean parents' behavior when called on a fake returned by withArgs", function () { + it("does not clean parents' behavior when called on a fake returned by withArgs", function() { var parentStub = createStub().returns(false); var childStub = parentStub.withArgs("lolz").returns(true); @@ -2590,7 +2775,7 @@ describe("stub", function () { assert.same(parentStub(), false); }); - it("cleans 'returnsArg' behavior", function () { + it("cleans 'returnsArg' behavior", function() { var stub = createStub().returnsArg(0); stub.resetBehavior(); @@ -2598,7 +2783,7 @@ describe("stub", function () { refute.defined(stub("defined")); }); - it("cleans 'returnsThis' behavior", function () { + it("cleans 'returnsThis' behavior", function() { var instance = {}; instance.stub = createStub.create(); instance.stub.returnsThis(); @@ -2608,7 +2793,7 @@ describe("stub", function () { refute.defined(instance.stub()); }); - it("cleans 'resolvesThis' behavior, so the stub does not resolve nor returns anything", function () { + it("cleans 'resolvesThis' behavior, so the stub does not resolve nor returns anything", function() { var instance = {}; instance.stub = createStub.create(); instance.stub.resolvesThis(); @@ -2618,8 +2803,8 @@ describe("stub", function () { refute.defined(instance.stub()); }); - describe("does not touch properties that are reset by 'reset'", function () { - it(".calledOnce", function () { + describe("does not touch properties that are reset by 'reset'", function() { + it(".calledOnce", function() { var stub = createStub(); stub(1); @@ -2628,7 +2813,7 @@ describe("stub", function () { assert(stub.calledOnce); }); - it("called multiple times", function () { + it("called multiple times", function() { var stub = createStub(); stub(1); stub(2); @@ -2647,7 +2832,7 @@ describe("stub", function () { assert.defined(stub.lastCall); }); - it("call order state", function () { + it("call order state", function() { var stubs = [createStub(), createStub()]; stubs[0](); stubs[1](); @@ -2657,7 +2842,7 @@ describe("stub", function () { assert(stubs[0].calledBefore(stubs[1])); }); - it("fakes returned by withArgs", function () { + it("fakes returned by withArgs", function() { var stub = createStub(); var fakeA = stub.withArgs("a"); var fakeB = stub.withArgs("b"); @@ -2675,69 +2860,86 @@ describe("stub", function () { }); }); - describe(".length", function () { - it("is zero by default", function () { + describe(".length", function() { + it("is zero by default", function() { var stub = createStub(); assert.equals(stub.length, 0); }); - it("matches the function length", function () { - var api = { someMethod: function (a, b, c) { return; } }; // eslint-disable-line no-unused-vars + it("matches the function length", function() { + var api = { + // eslint-disable-next-line no-unused-vars + someMethod: function(a, b, c) { + return; + } + }; var stub = createStub(api, "someMethod"); assert.equals(stub.length, 3); }); }); - describe(".createStubInstance", function () { - it("stubs existing methods", function () { - var Class = function () { return; }; - Class.prototype.method = function () { return; }; + describe(".createStubInstance", function() { + it("stubs existing methods", function() { + var Class = function() { + return; + }; + Class.prototype.method = function() { + return; + }; var stub = createStubInstance(Class); stub.method.returns(3); assert.equals(3, stub.method()); }); - it("doesn't stub fake methods", function () { - var Class = function () { return; }; + it("doesn't stub fake methods", function() { + var Class = function() { + return; + }; var stub = createStubInstance(Class); - assert.exception(function () { + assert.exception(function() { stub.method.returns(3); }); }); - it("doesn't call the constructor", function () { - var Class = function (a, b) { + it("doesn't call the constructor", function() { + var Class = function(a, b) { var c = a + b; throw c; }; - Class.prototype.method = function () { return; }; + Class.prototype.method = function() { + return; + }; var stub = createStubInstance(Class); - refute.exception(function () { + refute.exception(function() { stub.method(3); }); }); - it("retains non function values", function () { + it("retains non function values", function() { var TYPE = "some-value"; - var Class = function () { return; }; + var Class = function() { + return; + }; Class.prototype.type = TYPE; var stub = createStubInstance(Class); assert.equals(TYPE, stub.type); }); - it("has no side effects on the prototype", function () { + it("has no side effects on the prototype", function() { var proto = { - method: function () { + method: function() { throw new Error("error"); } }; - var Class = function () { return; }; + var Class = function() { + return; + }; Class.prototype = proto; var stub = createStubInstance(Class); @@ -2745,21 +2947,25 @@ describe("stub", function () { assert.exception(proto.method); }); - it("throws exception for non function params", function () { + it("throws exception for non function params", function() { var types = [{}, 3, "hi!"]; for (var i = 0; i < types.length; i++) { // yes, it's silly to create functions in a loop, it's also a test // eslint-disable-next-line no-loop-func, ie11/no-loop-func - assert.exception(function () { + assert.exception(function() { createStubInstance(types[i]); }); } }); - it("allows providing optional overrides", function () { - var Class = function () { return; }; - Class.prototype.method = function () { return; }; + it("allows providing optional overrides", function() { + var Class = function() { + return; + }; + Class.prototype.method = function() { + return; + }; var stub = createStubInstance(Class, { method: createStub().returns(3) @@ -2768,9 +2974,13 @@ describe("stub", function () { assert.equals(3, stub.method()); }); - it("allows providing optional returned values", function () { - var Class = function () { return; }; - Class.prototype.method = function () { return; }; + it("allows providing optional returned values", function() { + var Class = function() { + return; + }; + Class.prototype.method = function() { + return; + }; var stub = createStubInstance(Class, { method: 3 @@ -2779,20 +2989,27 @@ describe("stub", function () { assert.equals(3, stub.method()); }); - it("throws an exception when trying to override non-existing property", function () { - var Class = function () { return; }; - Class.prototype.method = function () { return; }; + it("throws an exception when trying to override non-existing property", function() { + var Class = function() { + return; + }; + Class.prototype.method = function() { + return; + }; - assert.exception(function () { - createStubInstance(Class, { - foo: createStub().returns(3) - }); - }, {message: "Cannot stub foo. Property does not exist!"}); + assert.exception( + function() { + createStubInstance(Class, { + foo: createStub().returns(3) + }); + }, + { message: "Cannot stub foo. Property does not exist!" } + ); }); }); - describe(".callThrough", function () { - it("does not call original function when arguments match conditional stub", function () { + describe(".callThrough", function() { + it("does not call original function when arguments match conditional stub", function() { // We need a function here because we can't wrap properties that are already stubs var callCount = 0; var originalFunc = function increaseCallCount() { @@ -2813,7 +3030,7 @@ describe("stub", function () { assert.equals(callCount, 0); }); - it("calls original function when arguments do not match conditional stub", function () { + it("calls original function when arguments do not match conditional stub", function() { // We need a function here because we can't wrap properties that are already stubs var callCount = 0; @@ -2836,7 +3053,7 @@ describe("stub", function () { assert.equals(callCount, 1); }); - it("calls original function with same arguments when call does not match conditional stub", function () { + it("calls original function with same arguments when call does not match conditional stub", function() { // We need a function here because we can't wrap properties that are already stubs var callArgs = []; @@ -2858,7 +3075,7 @@ describe("stub", function () { assert.equals(callArgs[0], "not foo"); }); - it("calls original function with same `this` reference when call does not match conditional stub", function () { + it("calls original function with same `this` reference when call does not match conditional stub", function() { // We need a function here because we can't wrap properties that are already stubs var reference = {}; @@ -2880,8 +3097,8 @@ describe("stub", function () { }); }); - describe(".get", function () { - it("allows users to stub getter functions for properties", function () { + describe(".get", function() { + it("allows users to stub getter functions for properties", function() { var myObj = { prop: "foo" }; @@ -2893,7 +3110,7 @@ describe("stub", function () { assert.equals(myObj.prop, "bar"); }); - it("allows users to stub getter functions for functions", function () { + it("allows users to stub getter functions for functions", function() { var myObj = { prop: function propGetter() { return "foo"; @@ -2907,7 +3124,7 @@ describe("stub", function () { assert.equals(myObj.prop, "bar"); }); - it("replaces old getters", function () { + it("replaces old getters", function() { var myObj = { get prop() { fail("should not call the old getter"); @@ -2922,7 +3139,7 @@ describe("stub", function () { assert.equals(myObj.prop, "bar"); }); - it("can restore stubbed setters for functions", function () { + it("can restore stubbed setters for functions", function() { var propFn = function propFn() { return "bar"; }; @@ -2942,7 +3159,7 @@ describe("stub", function () { assert.equals(myObj.prop, propFn); }); - it("can restore stubbed getters for properties", function () { + it("can restore stubbed getters for properties", function() { var myObj = { get prop() { return "bar"; @@ -2959,11 +3176,10 @@ describe("stub", function () { assert.equals(myObj.prop, "bar"); }); - }); - describe(".set", function () { - it("allows users to stub setter functions for properties", function () { + describe(".set", function() { + it("allows users to stub setter functions for properties", function() { var myObj = { prop: "foo" }; @@ -2977,7 +3193,7 @@ describe("stub", function () { assert.equals(myObj.example, "bar"); }); - it("allows users to stub setter functions for functions", function () { + it("allows users to stub setter functions for functions", function() { var myObj = { prop: function propSetter() { return "foo"; @@ -2993,8 +3209,9 @@ describe("stub", function () { assert.equals(myObj.example, "bar"); }); - it("replaces old setters", function () { - var myObj = { // eslint-disable-line accessor-pairs + it("replaces old setters", function() { + // eslint-disable-next-line accessor-pairs + var myObj = { set prop(val) { fail("should not call the old setter"); } @@ -3009,7 +3226,7 @@ describe("stub", function () { assert.equals(myObj.example, "bar"); }); - it("can restore stubbed setters for functions", function () { + it("can restore stubbed setters for functions", function() { var propFn = function propFn() { return "bar"; }; @@ -3029,8 +3246,9 @@ describe("stub", function () { assert.equals(myObj.prop, propFn); }); - it("can restore stubbed setters for properties", function () { - var myObj = { // eslint-disable-line accessor-pairs + it("can restore stubbed setters for properties", function() { + // eslint-disable-next-line accessor-pairs + var myObj = { set prop(val) { this.otherProp = "bar"; return "bar"; @@ -3048,11 +3266,10 @@ describe("stub", function () { myObj.prop = "foo"; assert.equals(myObj.otherProp, "bar"); }); - }); - describe(".value", function () { - it("allows stubbing property descriptor values", function () { + describe(".value", function() { + it("allows stubbing property descriptor values", function() { var myObj = { prop: "rawString" }; @@ -3061,7 +3278,7 @@ describe("stub", function () { assert.equals(myObj.prop, "newString"); }); - it("allows restoring stubbed property descriptor values", function () { + it("allows restoring stubbed property descriptor values", function() { var myObj = { prop: "rawString" }; @@ -3072,16 +3289,20 @@ describe("stub", function () { assert.equals(myObj.prop, "rawString"); }); - it("allows stubbing function static properties", function () { - var myFunc = function () { return; }; + it("allows stubbing function static properties", function() { + var myFunc = function() { + return; + }; myFunc.prop = "rawString"; createStub(myFunc, "prop").value("newString"); assert.equals(myFunc.prop, "newString"); }); - it("allows restoring function static properties", function () { - var myFunc = function () { return; }; + it("allows restoring function static properties", function() { + var myFunc = function() { + return; + }; myFunc.prop = "rawString"; var stub = createStub(myFunc, "prop").value("newString"); @@ -3090,7 +3311,7 @@ describe("stub", function () { assert.equals(myFunc.prop, "rawString"); }); - it("allows stubbing object props with configurable false", function () { + it("allows stubbing object props with configurable false", function() { var myObj = {}; Object.defineProperty(myObj, "prop", { configurable: false, @@ -3104,8 +3325,8 @@ describe("stub", function () { }); }); - describe(".id", function () { - it("should start with 'stub#'", function () { + describe(".id", function() { + it("should start with 'stub#'", function() { for (var i = 0; i < 10; i++) { assert.isTrue(createStub().id.indexOf("stub#") === 0); } diff --git a/test/test-helper.js b/test/test-helper.js index a0118b5b4..2c6bc942b 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -3,44 +3,40 @@ var referee = require("@sinonjs/referee"); referee.add("spy", { - assert: function (obj) { + assert: function(obj) { return obj !== null && typeof obj.calledWith === "function" && !obj.returns; }, assertMessage: "Expected object ${0} to be a spy function" }); referee.add("stub", { - assert: function (obj) { - return obj !== null && - typeof obj.calledWith === "function" && - typeof obj.returns === "function"; + assert: function(obj) { + return obj !== null && typeof obj.calledWith === "function" && typeof obj.returns === "function"; }, assertMessage: "Expected object ${0} to be a stub function" }); referee.add("mock", { - assert: function (obj) { - return obj !== null && - typeof obj.verify === "function" && - typeof obj.expects === "function"; + assert: function(obj) { + return obj !== null && typeof obj.verify === "function" && typeof obj.expects === "function"; }, assertMessage: "Expected object ${0} to be a mock" }); referee.add("fakeServer", { - assert: function (obj) { - return obj !== null && + assert: function(obj) { + return ( + obj !== null && Object.prototype.toString.call(obj.requests) === "[object Array]" && - typeof obj.respondWith === "function"; + typeof obj.respondWith === "function" + ); }, assertMessage: "Expected object ${0} to be a fake server" }); referee.add("clock", { - assert: function (obj) { - return obj !== null && - typeof obj.tick === "function" && - typeof obj.setTimeout === "function"; + assert: function(obj) { + return obj !== null && typeof obj.tick === "function" && typeof obj.setTimeout === "function"; }, assertMessage: "Expected object ${0} to be a clock" }); diff --git a/test/util/core/called-in-order-test.js b/test/util/core/called-in-order-test.js index 4d99a2f84..046d135e2 100644 --- a/test/util/core/called-in-order-test.js +++ b/test/util/core/called-in-order-test.js @@ -5,9 +5,21 @@ var calledInOrder = require("../../../lib/sinon/util/core/called-in-order"); var sinonStub = require("../../../lib/sinon/stub"); var assert = referee.assert; -var testObject1 = {someFunction: function () { return; }}; -var testObject2 = {otherFunction: function () { return; }}; -var testObject3 = {thirdFunction: function () { return; }}; +var testObject1 = { + someFunction: function() { + return; + } +}; +var testObject2 = { + otherFunction: function() { + return; + } +}; +var testObject3 = { + thirdFunction: function() { + return; + } +}; function testMethod() { testObject1.someFunction(); @@ -15,46 +27,40 @@ function testMethod() { testObject3.thirdFunction(); } -describe("util/core/calledInOrder", function () { - beforeEach(function () { +describe("util/core/calledInOrder", function() { + beforeEach(function() { sinonStub(testObject1, "someFunction"); sinonStub(testObject2, "otherFunction"); sinonStub(testObject3, "thirdFunction"); testMethod(); }); - afterEach(function () { + afterEach(function() { testObject1.someFunction.restore(); testObject2.otherFunction.restore(); testObject3.thirdFunction.restore(); }); - describe("With array parameter given", function () { - - it("returns true, if stubs were called in given order", function () { + describe("With array parameter given", function() { + it("returns true, if stubs were called in given order", function() { assert(calledInOrder([testObject1.someFunction, testObject2.otherFunction])); - assert(calledInOrder([testObject1.someFunction, testObject2.otherFunction, - testObject3.thirdFunction])); + assert(calledInOrder([testObject1.someFunction, testObject2.otherFunction, testObject3.thirdFunction])); }); - it("returns false, if stubs were called in wrong order", function () { + it("returns false, if stubs were called in wrong order", function() { assert(!calledInOrder([testObject2.otherFunction, testObject1.someFunction])); - assert(!calledInOrder([testObject2.otherFunction, testObject1.someFunction, - testObject3.thirdFunction])); + assert(!calledInOrder([testObject2.otherFunction, testObject1.someFunction, testObject3.thirdFunction])); }); }); - describe("With multiple parameters given", function () { - - it("returns true, if stubs were called in given order", function () { + describe("With multiple parameters given", function() { + it("returns true, if stubs were called in given order", function() { assert(calledInOrder(testObject1.someFunction, testObject2.otherFunction)); - assert(calledInOrder(testObject1.someFunction, testObject2.otherFunction, - testObject3.thirdFunction)); + assert(calledInOrder(testObject1.someFunction, testObject2.otherFunction, testObject3.thirdFunction)); }); - it("returns false, if stubs were called in wrong order", function () { + it("returns false, if stubs were called in wrong order", function() { assert(!calledInOrder(testObject2.otherFunction, testObject1.someFunction)); - assert(!calledInOrder(testObject2.otherFunction, testObject1.someFunction, - testObject3.thirdFunction)); + assert(!calledInOrder(testObject2.otherFunction, testObject1.someFunction, testObject3.thirdFunction)); }); }); }); diff --git a/test/util/core/color-test.js b/test/util/core/color-test.js index a974636e9..26d62f09f 100644 --- a/test/util/core/color-test.js +++ b/test/util/core/color-test.js @@ -13,11 +13,11 @@ function getColorMethods() { ]; } -describe("color", function () { - describe("when environment supports color", function () { +describe("color", function() { + describe("when environment supports color", function() { var color; - beforeEach(function () { + beforeEach(function() { color = proxyquire("../../../lib/sinon/color", { "supports-color": { stdout: true @@ -25,9 +25,9 @@ describe("color", function () { }); }); - getColorMethods().forEach(function (method) { - describe(method.name, function () { - it("should return a colored string", function () { + getColorMethods().forEach(function(method) { + describe(method.name, function() { + it("should return a colored string", function() { var string = "lorem ipsum"; var actual = color[method.name](string); @@ -37,10 +37,10 @@ describe("color", function () { }); }); - describe("when environment does not support color", function () { + describe("when environment does not support color", function() { var color; - beforeEach(function () { + beforeEach(function() { color = proxyquire("../../../lib/sinon/color", { "supports-color": { stdout: false @@ -48,9 +48,9 @@ describe("color", function () { }); }); - getColorMethods().forEach(function (method) { - describe(method.name, function () { - it("should return a regular string", function () { + getColorMethods().forEach(function(method) { + describe(method.name, function() { + it("should return a regular string", function() { var string = "lorem ipsum"; var actual = color[method.name](string); diff --git a/test/util/core/deep-equal-test.js b/test/util/core/deep-equal-test.js index 7a9426a63..34e3f8e16 100644 --- a/test/util/core/deep-equal-test.js +++ b/test/util/core/deep-equal-test.js @@ -6,77 +6,79 @@ var match = require("../../../lib/sinon/match"); var createSpy = require("../../../lib/sinon/spy").create; var assert = referee.assert; -describe("util/core/deepEqual", function () { - it("passes null", function () { +describe("util/core/deepEqual", function() { + it("passes null", function() { assert(deepEqual(null, null)); }); - it("fails null and object", function () { + it("fails null and object", function() { assert.isFalse(deepEqual(null, {})); }); - it("fails object and null", function () { + it("fails object and null", function() { assert.isFalse(deepEqual({}, null)); }); - it("fails error and object", function () { + it("fails error and object", function() { assert.isFalse(deepEqual(new Error(), {})); }); - it("fails object and error", function () { + it("fails object and error", function() { assert.isFalse(deepEqual({}, new Error())); }); - it("fails regexp and object", function () { + it("fails regexp and object", function() { assert.isFalse(deepEqual(/.*/, {})); }); - it("fails object and regexp", function () { + it("fails object and regexp", function() { assert.isFalse(deepEqual({}, /.*/)); }); - it("passes primitives", function () { + it("passes primitives", function() { assert(deepEqual(1, 1)); }); - it("passes same object", function () { + it("passes same object", function() { var object = {}; assert(deepEqual(object, object)); }); - it("passes same function", function () { - var func = function () { return; }; + it("passes same function", function() { + var func = function() { + return; + }; assert(deepEqual(func, func)); }); - it("passes same array", function () { + it("passes same array", function() { var arr = []; assert(deepEqual(arr, arr)); }); - it("passes same regexp", function () { + it("passes same regexp", function() { var regexp = /foo/; assert(deepEqual(regexp, regexp)); }); - it("passes same error", function () { + it("passes same error", function() { var error = new Error(); assert(deepEqual(error, error)); }); - it("passes equal arrays", function () { + it("passes equal arrays", function() { var arr1 = [1, 2, 3, "hey", "there"]; var arr2 = [1, 2, 3, "hey", "there"]; assert(deepEqual(arr1, arr2)); }); - it("passes equal arrays with custom properties", function () { + it("passes equal arrays with custom properties", function() { var arr1 = [1, 2, 3, "hey", "there"]; var arr2 = [1, 2, 3, "hey", "there"]; @@ -86,7 +88,7 @@ describe("util/core/deepEqual", function () { assert(deepEqual(arr1, arr2)); }); - it("fails arrays with unequal custom properties", function () { + it("fails arrays with unequal custom properties", function() { var arr1 = [1, 2, 3, "hey", "there"]; var arr2 = [1, 2, 3, "hey", "there"]; @@ -96,121 +98,116 @@ describe("util/core/deepEqual", function () { assert.isFalse(deepEqual(arr1, arr2)); }); - it("passes equal regexps", function () { + it("passes equal regexps", function() { var regexp1 = /foo/; var regexp2 = /foo/; assert(deepEqual(regexp1, regexp2)); - }); - it("fails unequal regexps", function () { + it("fails unequal regexps", function() { var regexp1 = /foo/; var regexp2 = /bar/; assert.isFalse(deepEqual(regexp1, regexp2)); - }); - it("passes equal regexps with same ignoreCase flags", function () { + it("passes equal regexps with same ignoreCase flags", function() { var regexp1 = /foo/i; var regexp2 = /foo/i; assert(deepEqual(regexp1, regexp2)); - }); - it("fails unequal regexps with different ignoreCase flags", function () { + it("fails unequal regexps with different ignoreCase flags", function() { var regexp1 = /foo/i; var regexp2 = /foo/; assert.isFalse(deepEqual(regexp1, regexp2)); - }); - it("passes equal regexps with same multiline flags", function () { + it("passes equal regexps with same multiline flags", function() { var regexp1 = /foo/m; var regexp2 = /foo/m; assert(deepEqual(regexp1, regexp2)); - }); - it("fails unequal regexps with different multiline flags", function () { + it("fails unequal regexps with different multiline flags", function() { var regexp1 = /foo/m; var regexp2 = /foo/; assert.isFalse(deepEqual(regexp1, regexp2)); }); - it("passes equal regexps with same global flags", function () { + it("passes equal regexps with same global flags", function() { var regexp1 = /foo/g; var regexp2 = /foo/g; assert(deepEqual(regexp1, regexp2)); }); - it("fails unequal regexps with different global flags", function () { + it("fails unequal regexps with different global flags", function() { var regexp1 = /foo/g; var regexp2 = /foo/; assert.isFalse(deepEqual(regexp1, regexp2)); }); - it("passes equal regexps with multiple flags", function () { + it("passes equal regexps with multiple flags", function() { var regexp1 = /bar/im; var regexp2 = /bar/im; assert(deepEqual(regexp1, regexp2)); }); - it("fails unequal regexps with multiple flags", function () { + it("fails unequal regexps with multiple flags", function() { var regexp1 = /bar/im; - var regexp2 = /bar/ig; + var regexp2 = /bar/gi; assert.isFalse(deepEqual(regexp1, regexp2)); }); - it("fails unequal errors", function () { + it("fails unequal errors", function() { var error1 = new Error(); var error2 = new Error(); assert.isFalse(deepEqual(error1, error2)); }); - it("passes NaN and NaN", function () { + it("passes NaN and NaN", function() { assert(deepEqual(NaN, NaN)); }); - it("passes equal objects", function () { + it("passes equal objects", function() { var obj1 = { a: 1, b: 2, c: 3, d: "hey", e: "there" }; var obj2 = { b: 2, c: 3, a: 1, d: "hey", e: "there" }; assert(deepEqual(obj1, obj2)); }); - it("fails unequal objects with undefined properties with different names", function () { - var obj1 = {a: 1, b: 2, c: 3}; - var obj2 = {a: 1, b: 2, foo: undefined}; + it("fails unequal objects with undefined properties with different names", function() { + var obj1 = { a: 1, b: 2, c: 3 }; + var obj2 = { a: 1, b: 2, foo: undefined }; assert.isFalse(deepEqual(obj1, obj2)); }); - it("fails unequal objects with undefined properties with different names (different arg order)", function () { - var obj1 = {a: 1, b: 2, foo: undefined}; - var obj2 = {a: 1, b: 2, c: 3}; + it("fails unequal objects with undefined properties with different names (different arg order)", function() { + var obj1 = { a: 1, b: 2, foo: undefined }; + var obj2 = { a: 1, b: 2, c: 3 }; assert.isFalse(deepEqual(obj1, obj2)); }); - it("passes equal dates", function () { + it("passes equal dates", function() { var date1 = new Date(2012, 3, 5); var date2 = new Date(2012, 3, 5); assert(deepEqual(date1, date2)); }); - it("fails different dates", function () { + it("fails different dates", function() { var date1 = new Date(2012, 3, 5); var date2 = new Date(2013, 3, 5); @@ -218,22 +215,21 @@ describe("util/core/deepEqual", function () { }); if (typeof document !== "undefined") { - describe("in browsers", function () { - - it("passes same DOM elements", function () { + describe("in browsers", function() { + it("passes same DOM elements", function() { var element = document.createElement("div"); assert(deepEqual(element, element)); }); - it("fails different DOM elements", function () { + it("fails different DOM elements", function() { var element = document.createElement("div"); var el = document.createElement("div"); assert.isFalse(deepEqual(element, el)); }); - it("does not modify DOM elements when comparing them", function () { + it("does not modify DOM elements when comparing them", function() { var el = document.createElement("div"); document.body.appendChild(el); deepEqual(el, {}); @@ -244,8 +240,10 @@ describe("util/core/deepEqual", function () { }); } - it("passes deep objects", function () { - var func = function () { return; }; + it("passes deep objects", function() { + var func = function() { + return; + }; var obj1 = { a: 1, @@ -255,9 +253,14 @@ describe("util/core/deepEqual", function () { e: "there", f: func, g: { - a1: [1, 2, "3", { - prop: [func, "b"] - }] + a1: [ + 1, + 2, + "3", + { + prop: [func, "b"] + } + ] } }; @@ -269,16 +272,21 @@ describe("util/core/deepEqual", function () { e: "there", f: func, g: { - a1: [1, 2, "3", { - prop: [func, "b"] - }] + a1: [ + 1, + 2, + "3", + { + prop: [func, "b"] + } + ] } }; assert(deepEqual(obj1, obj2)); }); - it("passes object without prototype compared to equal object with prototype", function () { + it("passes object without prototype compared to equal object with prototype", function() { var obj1 = Object.create(null); obj1.a = 1; obj1.b = 2; @@ -289,7 +297,7 @@ describe("util/core/deepEqual", function () { assert(deepEqual(obj1, obj2)); }); - it("passes object with prototype compared to equal object without prototype", function () { + it("passes object with prototype compared to equal object without prototype", function() { var obj1 = { a: 1, b: 2, c: "hey" }; var obj2 = Object.create(null); @@ -300,7 +308,7 @@ describe("util/core/deepEqual", function () { assert(deepEqual(obj1, obj2)); }); - it("passes equal objects without prototypes", function () { + it("passes equal objects without prototypes", function() { var obj1 = Object.create(null); obj1.a = 1; obj1.b = 2; @@ -314,14 +322,14 @@ describe("util/core/deepEqual", function () { assert(deepEqual(obj1, obj2)); }); - it("passes equal objects that override hasOwnProperty", function () { + it("passes equal objects that override hasOwnProperty", function() { var obj1 = { a: 1, b: 2, c: "hey", hasOwnProperty: "silly" }; var obj2 = { a: 1, b: 2, c: "hey", hasOwnProperty: "silly" }; assert(deepEqual(obj1, obj2)); }); - it("does not run matchers against each other when using a matcher library", function () { + it("does not run matchers against each other when using a matcher library", function() { var matchDeepEqual = deepEqual.use(match); var spyA = createSpy(); @@ -336,7 +344,7 @@ describe("util/core/deepEqual", function () { assert.equals(spyB.callCount, 0); }); - it("strictly compares instances when passed two matchers and using a matcher library", function () { + it("strictly compares instances when passed two matchers and using a matcher library", function() { var matchDeepEqual = deepEqual.use(match); var matchA = match(function a() { @@ -353,7 +361,7 @@ describe("util/core/deepEqual", function () { assert.isFalse(matchDeepEqual(matchA, matchB)); }); - it("handles shallow cyclic objects", function () { + it("handles shallow cyclic objects", function() { var a = { foo: "bar" }; @@ -367,23 +375,23 @@ describe("util/core/deepEqual", function () { assert(deepEqual(a, b)); }); - it("handles deep cyclic objects", function () { + it("handles deep cyclic objects", function() { var a = { foo: "bar", - key: { } + key: {} }; a.key.value = a; var b = { foo: "bar", - key: { } + key: {} }; b.key.value = b; assert(deepEqual(a, b)); }); - it("handles cyclic objects when a matcher provided", function () { + it("handles cyclic objects when a matcher provided", function() { var matchDeepEqual = deepEqual.use(match); var a = { @@ -398,5 +406,4 @@ describe("util/core/deepEqual", function () { assert(matchDeepEqual(a, b)); }); - }); diff --git a/test/util/core/every-test.js b/test/util/core/every-test.js index c309245b9..70fafca83 100644 --- a/test/util/core/every-test.js +++ b/test/util/core/every-test.js @@ -5,29 +5,29 @@ var createSpy = require("../../../lib/sinon/spy"); var every = require("../../../lib/sinon/util/core/every"); var assert = referee.assert; -describe("util/core/every", function () { - it("returns true when the callback function returns true for every element in an iterable", function () { +describe("util/core/every", function() { + it("returns true when the callback function returns true for every element in an iterable", function() { var obj = [true, true, true, true]; - var allTrue = every(obj, function (val) { + var allTrue = every(obj, function(val) { return val; }); assert(allTrue); }); - it("returns false when the callback function returns false for any element in an iterable", function () { + it("returns false when the callback function returns false for any element in an iterable", function() { var obj = [true, true, true, false]; - var result = every(obj, function (val) { + var result = every(obj, function(val) { return val; }); assert.isFalse(result); }); - it("calls the given callback once for each item in an iterable until it returns false", function () { + it("calls the given callback once for each item in an iterable until it returns false", function() { var iterableOne = [true, true, true, true]; var iterableTwo = [true, true, false, true]; - var callback = createSpy(function (val) { + var callback = createSpy(function(val) { return val; }); diff --git a/test/util/core/format-test.js b/test/util/core/format-test.js index bc08b5440..4d1e274d5 100644 --- a/test/util/core/format-test.js +++ b/test/util/core/format-test.js @@ -5,38 +5,43 @@ var sinon = require("../../../lib/sinon"); var format = require("../../../lib/sinon/util/core/format"); var assert = referee.assert; -describe("util/core/format", function () { - it("formats with formatio by default", function () { +describe("util/core/format", function() { + it("formats with formatio by default", function() { assert.equals(format({ id: 42 }), "{ id: 42 }"); }); // eslint-disable-next-line mocha/no-skipped-tests - it.skip("should configure formatio to use maximum 250 entries", function () { + it.skip("should configure formatio to use maximum 250 entries", function() { // not sure how we can verify this integration with the current setup // where sinon.js calls formatio as part of its loading // extracting sinon.format into a separate module would make this a lot // easier }); - it("formats strings without quotes", function () { + it("formats strings without quotes", function() { assert.equals(format("Hey"), "Hey"); }); - describe("format.setFormatter", function () { - it("sets custom formatter", function () { - format.setFormatter(function () { return "formatted"; }); + describe("format.setFormatter", function() { + it("sets custom formatter", function() { + format.setFormatter(function() { + return "formatted"; + }); assert.equals(format("Hey"), "formatted"); }); - it("throws if custom formatter is not a function", function () { - assert.exception(function () { - format.setFormatter("foo"); - }, { - message: "format.setFormatter must be called with a function" - }); + it("throws if custom formatter is not a function", function() { + assert.exception( + function() { + format.setFormatter("foo"); + }, + { + message: "format.setFormatter must be called with a function" + } + ); }); - it("exposes method on sinon", function () { + it("exposes method on sinon", function() { assert.equals(sinon.setFormatter, format.setFormatter); }); }); diff --git a/test/util/core/function-to-string-test.js b/test/util/core/function-to-string-test.js index 91433ffff..0953daccd 100644 --- a/test/util/core/function-to-string-test.js +++ b/test/util/core/function-to-string-test.js @@ -5,15 +5,17 @@ var createSpy = require("../../../lib/sinon/spy"); var functionToString = require("../../../lib/sinon/util/core/function-to-string"); var assert = referee.assert; -describe("util/core/functionToString", function () { - it("returns function's displayName property", function () { - var fn = function () { return; }; +describe("util/core/functionToString", function() { + it("returns function's displayName property", function() { + var fn = function() { + return; + }; fn.displayName = "Larry"; assert.equals(functionToString.call(fn), "Larry"); }); - it("guesses name from last call's this object", function () { + it("guesses name from last call's this object", function() { var obj = {}; obj.doStuff = createSpy(); obj.doStuff.call({}); @@ -22,7 +24,7 @@ describe("util/core/functionToString", function () { assert.equals(functionToString.call(obj.doStuff), "doStuff"); }); - it("guesses name from any call where property can be located", function () { + it("guesses name from any call where property can be located", function() { var obj = {}; var otherObj = { id: 42 }; diff --git a/test/util/core/get-config-test.js b/test/util/core/get-config-test.js index 736a88f12..7e7c26c79 100644 --- a/test/util/core/get-config-test.js +++ b/test/util/core/get-config-test.js @@ -6,9 +6,9 @@ var defaultConfig = require("../../../lib/sinon/util/core/default-config"); var assert = referee.assert; var refute = referee.refute; -describe("core/util/getConfig", function () { - describe(".getConfig", function () { - it("gets copy of default config", function () { +describe("core/util/getConfig", function() { + describe(".getConfig", function() { + it("gets copy of default config", function() { var config = getConfig(); refute.same(config, defaultConfig); @@ -19,7 +19,7 @@ describe("core/util/getConfig", function () { assert.equals(config.useFakeServer, defaultConfig.useFakeServer); }); - it("should override specified properties", function () { + it("should override specified properties", function() { var config = getConfig({ properties: ["stub", "mock"], useFakeServer: false diff --git a/test/util/core/get-next-tick-test.js b/test/util/core/get-next-tick-test.js index 3c0a90ba1..829926a75 100644 --- a/test/util/core/get-next-tick-test.js +++ b/test/util/core/get-next-tick-test.js @@ -4,22 +4,26 @@ var referee = require("@sinonjs/referee"); var getNextTick = require("../../../lib/sinon/util/core/get-next-tick"); var assert = referee.assert; -describe("util/core/get-next-tick", function () { - it("should use process.nextTick when available", function () { +describe("util/core/get-next-tick", function() { + it("should use process.nextTick when available", function() { var mockProcess = { - nextTick: function () { return; } + nextTick: function() { + return; + } }; assert.same(getNextTick(mockProcess), mockProcess.nextTick); }); - it("should use setImmediate when process.nextTick is not available", function () { - function mockSetImmediate() { return; } + it("should use setImmediate when process.nextTick is not available", function() { + function mockSetImmediate() { + return; + } assert.same(getNextTick(undefined, mockSetImmediate), mockSetImmediate); }); - it("should fallback to setTimeout", function () { + it("should fallback to setTimeout", function() { var nextTick = getNextTick(undefined, undefined); assert.isFunction(nextTick); diff --git a/test/util/core/iterable-to-string-test.js b/test/util/core/iterable-to-string-test.js index 683c44ab5..61b5cddc6 100644 --- a/test/util/core/iterable-to-string-test.js +++ b/test/util/core/iterable-to-string-test.js @@ -4,8 +4,8 @@ var referee = require("@sinonjs/referee"); var iterableToString = require("../../../lib/sinon/util/core/iterable-to-string"); var assert = referee.assert; -describe("util/core/iterable-to-string", function () { - it("returns an String representation of Array objects", function () { +describe("util/core/iterable-to-string", function() { + it("returns an String representation of Array objects", function() { var arr = [1, "one", true, undefined, null]; var expected = "1,'one',true,undefined,null"; @@ -13,25 +13,21 @@ describe("util/core/iterable-to-string", function () { }); if (typeof Map === "function") { - it("returns an String representation of Map objects", function () { + it("returns an String representation of Map objects", function() { var map = new Map(); map.set(1, 1); map.set("one", "one"); map.set(true, true); map.set(undefined, undefined); map.set(null, null); - var expected = "[1,1]," + - "['one','one']," + - "[true,true]," + - "[undefined,undefined]," + - "[null,null]"; + var expected = "[1,1]," + "['one','one']," + "[true,true]," + "[undefined,undefined]," + "[null,null]"; assert.equals(iterableToString(map), expected); }); } if (typeof Set === "function") { - it("returns an String representation of Set objects", function () { + it("returns an String representation of Set objects", function() { var set = new Set(); set.add(1); set.add("one"); diff --git a/test/util/core/next-tick-test.js b/test/util/core/next-tick-test.js index 576dfcba2..b8eb13b60 100644 --- a/test/util/core/next-tick-test.js +++ b/test/util/core/next-tick-test.js @@ -7,40 +7,40 @@ var assert = referee.assert; var hasNextTick = typeof process === "object" && typeof process.nextTick === "function"; var hasSetImmediate = typeof setImmediate === "function"; -describe("util/core/next-tick", function () { - describe("browser environment", function () { - before(function () { +describe("util/core/next-tick", function() { + describe("browser environment", function() { + before(function() { if (hasNextTick || hasSetImmediate) { this.skip(); } }); - it("should use fallback", function () { + it("should use fallback", function() { assert.isFunction(nextTick); assert.contains(String(nextTick), "setTimeout("); }); }); - describe("modern node environment", function () { - before(function () { + describe("modern node environment", function() { + before(function() { if (!hasNextTick) { this.skip(); } }); - it("should use process.nextTick", function () { + it("should use process.nextTick", function() { assert.same(nextTick, process.nextTick); }); }); - describe("old node environment", function () { - before(function () { + describe("old node environment", function() { + before(function() { if (hasNextTick || !hasSetImmediate) { this.skip(); } }); - it("should use setImmediate", function () { + it("should use setImmediate", function() { assert.same(nextTick, setImmediate); }); }); diff --git a/test/util/core/restore-test.js b/test/util/core/restore-test.js index 8e33635b5..beecb000e 100644 --- a/test/util/core/restore-test.js +++ b/test/util/core/restore-test.js @@ -5,11 +5,17 @@ var restore = require("../../../lib/sinon/util/core/restore"); var createStub = require("../../../lib/sinon/stub"); var assert = referee.assert; -describe("util/core/restore", function () { - it("restores all methods of supplied object", function () { - var methodA = function () { return; }; - var methodB = function () { return; }; - var nonEnumerableMethod = function () { return; }; +describe("util/core/restore", function() { + it("restores all methods of supplied object", function() { + var methodA = function() { + return; + }; + var methodB = function() { + return; + }; + var nonEnumerableMethod = function() { + return; + }; var obj = { methodA: methodA, methodB: methodB, nonEnumerableMethod: nonEnumerableMethod }; Object.defineProperty(obj, "nonEnumerableMethod", { enumerable: false @@ -23,9 +29,13 @@ describe("util/core/restore", function () { assert.same(obj.nonEnumerableMethod, nonEnumerableMethod); }); - it("only restores restorable methods", function () { - var stubbedMethod = function () { return; }; - var vanillaMethod = function () { return; }; + it("only restores restorable methods", function() { + var stubbedMethod = function() { + return; + }; + var vanillaMethod = function() { + return; + }; var obj = { stubbedMethod: stubbedMethod, vanillaMethod: vanillaMethod }; createStub(obj, "stubbedMethod"); @@ -34,8 +44,10 @@ describe("util/core/restore", function () { assert.same(obj.stubbedMethod, stubbedMethod); }); - it("restores a single stubbed method", function () { - var method = function () { return; }; + it("restores a single stubbed method", function() { + var method = function() { + return; + }; var obj = { method: method }; createStub(obj); diff --git a/test/util/core/times-in-words-test.js b/test/util/core/times-in-words-test.js index a57ae5599..753acaca5 100644 --- a/test/util/core/times-in-words-test.js +++ b/test/util/core/times-in-words-test.js @@ -4,23 +4,23 @@ var referee = require("@sinonjs/referee"); var timesInWords = require("../../../lib/sinon/util/core/times-in-words"); var assert = referee.assert; -describe("util/core/timesInWords", function () { - it("should return \"once\" for input of 1", function () { +describe("util/core/timesInWords", function() { + it('should return "once" for input of 1', function() { var result = timesInWords(1); assert.equals(result, "once"); }); - it("should return \"twice\" for input of 2", function () { + it('should return "twice" for input of 2', function() { var result = timesInWords(2); assert.equals(result, "twice"); }); - it("should return \"thrice\" for input of 3", function () { + it('should return "thrice" for input of 3', function() { var result = timesInWords(3); assert.equals(result, "thrice"); }); - it("should return \"n times\" for n larger than 3", function () { + it('should return "n times" for n larger than 3', function() { var result, i; for (i = 4; i < 100; i++) { @@ -29,7 +29,7 @@ describe("util/core/timesInWords", function () { } }); - it("should return \"0 times\" for falsy input", function () { + it('should return "0 times" for falsy input', function() { var falsies = [0, NaN, null, false, undefined, ""]; var result, i; diff --git a/test/util/core/typeOf-test.js b/test/util/core/typeOf-test.js index e9f93fe21..888da7f99 100644 --- a/test/util/core/typeOf-test.js +++ b/test/util/core/typeOf-test.js @@ -4,44 +4,49 @@ var referee = require("@sinonjs/referee"); var sinonTypeOf = require("../../../lib/sinon/util/core/typeOf"); var assert = referee.assert; -describe("typeOf", function () { - it("returns boolean", function () { +describe("typeOf", function() { + it("returns boolean", function() { assert.equals(sinonTypeOf(false), "boolean"); }); - it("returns string", function () { + it("returns string", function() { assert.equals(sinonTypeOf("Sinon.JS"), "string"); }); - it("returns number", function () { + it("returns number", function() { assert.equals(sinonTypeOf(123), "number"); }); - it("returns object", function () { + it("returns object", function() { assert.equals(sinonTypeOf({}), "object"); }); - it("returns function", function () { - assert.equals(sinonTypeOf(function () { return; }), "function"); + it("returns function", function() { + assert.equals( + sinonTypeOf(function() { + return; + }), + "function" + ); }); - it("returns undefined", function () { + it("returns undefined", function() { assert.equals(sinonTypeOf(undefined), "undefined"); }); - it("returns null", function () { + it("returns null", function() { assert.equals(sinonTypeOf(null), "null"); }); - it("returns array", function () { + it("returns array", function() { assert.equals(sinonTypeOf([]), "array"); }); - it("returns regexp", function () { + it("returns regexp", function() { assert.equals(sinonTypeOf(/.*/), "regexp"); }); - it("returns date", function () { + it("returns date", function() { assert.equals(sinonTypeOf(new Date()), "date"); }); }); diff --git a/test/util/core/walk-test.js b/test/util/core/walk-test.js index f8f3f1332..19cc9ed34 100644 --- a/test/util/core/walk-test.js +++ b/test/util/core/walk-test.js @@ -5,8 +5,8 @@ var walk = require("../../../lib/sinon/util/core/walk"); var createSpy = require("../../../lib/sinon/spy"); var assert = referee.assert; -describe("util/core/walk", function () { - it("should call iterator with value, key, and obj, with context as the receiver", function () { +describe("util/core/walk", function() { + it("should call iterator with value, key, and obj, with context as the receiver", function() { var target = Object.create(null); var rcvr = {}; var iterator = createSpy(); @@ -22,7 +22,7 @@ describe("util/core/walk", function () { assert(iterator.calledWithExactly("foo", target)); }); - it("should work with non-enumerable properties", function () { + it("should work with non-enumerable properties", function() { var target = Object.create(null); var iterator = createSpy(); @@ -38,7 +38,7 @@ describe("util/core/walk", function () { assert(iterator.calledWith("foo")); }); - it("should walk the prototype chain of an object", function () { + it("should walk the prototype chain of an object", function() { var parentProto, proto, target, iterator; parentProto = Object.create(null, { @@ -84,8 +84,10 @@ describe("util/core/walk", function () { assert(iterator.calledWith("enumerableParentProp", parentProto)); }); - it("should not invoke getters on the original receiving object", function () { - var Target = function Target() { return; }; + it("should not invoke getters on the original receiving object", function() { + var Target = function Target() { + return; + }; var getter = createSpy(); Object.defineProperty(Target.prototype, "computedFoo", { enumerable: true, @@ -100,7 +102,7 @@ describe("util/core/walk", function () { assert(getter.notCalled); }); - it("should fall back to for..in if getOwnPropertyNames is not available", function () { + it("should fall back to for..in if getOwnPropertyNames is not available", function() { var getOwnPropertyNames = Object.getOwnPropertyNames; var Target = function Target() { this.hello = "world"; @@ -124,7 +126,8 @@ describe("util/core/walk", function () { } /* eslint-enable guard-for-in */ - try { // eslint-disable-line no-restricted-syntax + // eslint-disable-next-line no-restricted-syntax + try { walk(target, iterator, rcvr); assert.equals(iterator.callCount, numCalls); assert(iterator.alwaysCalledOn(rcvr)); @@ -139,22 +142,26 @@ describe("util/core/walk", function () { assert.isNull(err, "walk tests failed with message '" + (err && err.message) + "'"); }); - it("does not walk the same property twice", function () { + it("does not walk the same property twice", function() { var parent = { - func: function parentFunc() { return; } + func: function parentFunc() { + return; + } }; var child = Object.create(parent); - child.func = function childFunc() { return; }; + child.func = function childFunc() { + return; + }; var iterator = createSpy(); walk(child, iterator); - var propertyNames = iterator.args.map(function (call) { + var propertyNames = iterator.args.map(function(call) { return call[0]; }); // make sure that each property name only exists once - propertyNames.forEach(function (name, index) { + propertyNames.forEach(function(name, index) { assert.equals(index, propertyNames.lastIndexOf(name)); }); }); diff --git a/test/util/core/wrap-method-test.js b/test/util/core/wrap-method-test.js index db6c87830..714dceaa5 100644 --- a/test/util/core/wrap-method-test.js +++ b/test/util/core/wrap-method-test.js @@ -7,12 +7,18 @@ var createStub = require("../../../lib/sinon/stub"); var assert = referee.assert; var refute = referee.refute; -describe("util/core/wrapMethod", function () { - beforeEach(function () { - this.method = function () { return; }; - this.getter = function () { return; }; - this.setter = function () { return; }; - this.object = {method: this.method}; +describe("util/core/wrapMethod", function() { + beforeEach(function() { + this.method = function() { + return; + }; + this.getter = function() { + return; + }; + this.setter = function() { + return; + }; + this.object = { method: this.method }; Object.defineProperty(this.object, "property", { get: this.getter, set: this.setter, @@ -20,49 +26,66 @@ describe("util/core/wrapMethod", function () { }); }); - it("is function", function () { + it("is function", function() { assert.isFunction(wrapMethod); }); - it("throws if first argument is not object", function () { - assert.exception(function () { - wrapMethod(); - }, {name: "TypeError"}); + it("throws if first argument is not object", function() { + assert.exception( + function() { + wrapMethod(); + }, + { name: "TypeError" } + ); }); - it("throws if object defines property but is not function", function () { + it("throws if object defines property but is not function", function() { this.object.prop = 42; var object = this.object; - assert.exception(function () { - wrapMethod(object, "prop", function () { return; }); - }, {name: "TypeError"}); + assert.exception( + function() { + wrapMethod(object, "prop", function() { + return; + }); + }, + { name: "TypeError" } + ); }); - it("throws Symbol() if object defines property but is not function", function () { + it("throws Symbol() if object defines property but is not function", function() { if (typeof Symbol === "function") { var symbol = Symbol(); var object = {}; object[symbol] = 42; - assert.exception(function () { - wrapMethod(object, symbol, function () { return; }); - }, function (err) { - return err.message === "Attempted to wrap number property Symbol() as function"; - }); + assert.exception( + function() { + wrapMethod(object, symbol, function() { + return; + }); + }, + function(err) { + return err.message === "Attempted to wrap number property Symbol() as function"; + } + ); } }); - it("throws if object does not define property", function () { + it("throws if object does not define property", function() { var object = this.object; - assert.exception(function () { - wrapMethod(object, "prop", function () { return; }); + assert.exception(function() { + wrapMethod(object, "prop", function() { + return; + }); }); assert.exception( - function () { - wrapMethod(object, "prop", function () { return; }); + function() { + wrapMethod(object, "prop", function() { + return; + }); }, { message: /Attempted to wrap .* property .* as function/ @@ -70,127 +93,185 @@ describe("util/core/wrapMethod", function () { ); }); - it("throws if third argument is missing", function () { + it("throws if third argument is missing", function() { var object = this.object; - assert.exception(function () { - wrapMethod(object, "method"); - }, {name: "TypeError"}); + assert.exception( + function() { + wrapMethod(object, "method"); + }, + { name: "TypeError" } + ); }); - it("throws if third argument is not a function or a property descriptor", function () { + it("throws if third argument is not a function or a property descriptor", function() { var object = this.object; - assert.exception(function () { - wrapMethod(object, "method", 1); - }, {name: "TypeError"}); + assert.exception( + function() { + wrapMethod(object, "method", 1); + }, + { name: "TypeError" } + ); }); - it("replaces object method", function () { - wrapMethod(this.object, "method", function () { return; }); + it("replaces object method", function() { + wrapMethod(this.object, "method", function() { + return; + }); refute.same(this.method, this.object.method); assert.isFunction(this.object.method); }); - it("replaces getter", function () { - wrapMethod(this.object, "property", { get: function () { return; } }); + it("replaces getter", function() { + wrapMethod(this.object, "property", { + get: function() { + return; + } + }); refute.same(this.getter, Object.getOwnPropertyDescriptor(this.object, "property").get); assert.isFunction(Object.getOwnPropertyDescriptor(this.object, "property").get); }); - it("replaces setter", function () { - wrapMethod(this.object, "property", { // eslint-disable-line accessor-pairs - set: function () { return; } + it("replaces setter", function() { + wrapMethod(this.object, "property", { + // eslint-disable-line accessor-pairs + set: function() { + return; + } }); refute.same(this.setter, Object.getOwnPropertyDescriptor(this.object, "property").set); assert.isFunction(Object.getOwnPropertyDescriptor(this.object, "property").set); }); - it("throws if method is already wrapped", function () { - wrapMethod(this.object, "method", function () { return; }); + it("throws if method is already wrapped", function() { + wrapMethod(this.object, "method", function() { + return; + }); - assert.exception(function () { - wrapMethod(this.object, "method", function () { return; }); - }, {name: "TypeError"}); + assert.exception( + function() { + wrapMethod(this.object, "method", function() { + return; + }); + }, + { name: "TypeError" } + ); }); - it("throws Symbol if method is already wrapped", function () { + it("throws Symbol if method is already wrapped", function() { if (typeof Symbol === "function") { var symbol = Symbol(); var object = {}; - object[symbol] = function () { return; }; - wrapMethod(object, symbol, function () { return; }); - - assert.exception(function () { - wrapMethod(object, symbol, function () { return; }); - }, function (err) { - return err.message === "Attempted to wrap Symbol() which is already wrapped"; + object[symbol] = function() { + return; + }; + wrapMethod(object, symbol, function() { + return; }); + + assert.exception( + function() { + wrapMethod(object, symbol, function() { + return; + }); + }, + function(err) { + return err.message === "Attempted to wrap Symbol() which is already wrapped"; + } + ); } }); - it("throws if property descriptor is already wrapped", function () { - wrapMethod(this.object, "property", { get: function () { return; } }); + it("throws if property descriptor is already wrapped", function() { + wrapMethod(this.object, "property", { + get: function() { + return; + } + }); - assert.exception(function () { - wrapMethod(this.object, "property", { get: function () { return; } }); - }, {name: "TypeError"}); + assert.exception( + function() { + wrapMethod(this.object, "property", { + get: function() { + return; + } + }); + }, + { name: "TypeError" } + ); }); - it("throws if method is already a spy", function () { + it("throws if method is already a spy", function() { var object = { method: createSpy() }; - assert.exception(function () { - wrapMethod(object, "method", function () { return; }); - }, {name: "TypeError"}); + assert.exception( + function() { + wrapMethod(object, "method", function() { + return; + }); + }, + { name: "TypeError" } + ); }); - it("throws if Symbol method is already a spy", function () { + it("throws if Symbol method is already a spy", function() { if (typeof Symbol === "function") { var symbol = Symbol(); var object = {}; object[symbol] = createSpy(); - assert.exception(function () { - wrapMethod(object, symbol, function () { return; }); - }, function (err) { - return err.message === "Attempted to wrap Symbol() which is already spied on"; - }); + assert.exception( + function() { + wrapMethod(object, symbol, function() { + return; + }); + }, + function(err) { + return err.message === "Attempted to wrap Symbol() which is already spied on"; + } + ); } }); - describe("originating stack traces", function () { - beforeEach(function () { + describe("originating stack traces", function() { + beforeEach(function() { this.oldError = Error; this.oldTypeError = TypeError; var i = 0; // eslint-disable-next-line no-global-assign, no-native-reassign - Error = TypeError = function () { + Error = TypeError = function() { this.stack = ":STACK" + ++i + ":"; }; }); - afterEach(function () { + afterEach(function() { // eslint-disable-next-line no-global-assign, no-native-reassign Error = this.oldError; // eslint-disable-next-line no-global-assign, no-native-reassign TypeError = this.oldTypeError; }); - it("throws with stack trace showing original wrapMethod call", function () { - var object = { method: function () { return; } }; - wrapMethod(object, "method", function () { + it("throws with stack trace showing original wrapMethod call", function() { + var object = { + method: function() { + return; + } + }; + wrapMethod(object, "method", function() { return "original"; }); assert.exception( - function () { - wrapMethod(object, "method", function () { return; }); + function() { + wrapMethod(object, "method", function() { + return; + }); }, { stack: ":STACK2:\n--------------\n:STACK1:" @@ -200,27 +281,41 @@ describe("util/core/wrapMethod", function () { }); if (typeof window !== "undefined") { - describe("in browser", function () { - it("does not throw if object is window object", function () { - window.sinonTestMethod = function () { return; }; - refute.exception(function () { - wrapMethod(window, "sinonTestMethod", function () { return; }); + describe("in browser", function() { + it("does not throw if object is window object", function() { + window.sinonTestMethod = function() { + return; + }; + refute.exception(function() { + wrapMethod(window, "sinonTestMethod", function() { + return; + }); }); }); }); } - it("mirrors function properties", function () { - var object = { method: function () { return; } }; + it("mirrors function properties", function() { + var object = { + method: function() { + return; + } + }; object.method.prop = 42; - wrapMethod(object, "method", function () { return; }); + wrapMethod(object, "method", function() { + return; + }); assert.equals(object.method.prop, 42); }); - it("does not mirror and overwrite existing properties", function () { - var object = { method: function () { return; } }; + it("does not mirror and overwrite existing properties", function() { + var object = { + method: function() { + return; + } + }; object.method.called = 42; createStub(object, "method"); @@ -228,49 +323,65 @@ describe("util/core/wrapMethod", function () { assert.isFalse(object.method.called); }); - describe("wrapped method", function () { - beforeEach(function () { - this.method = function () { return; }; + describe("wrapped method", function() { + beforeEach(function() { + this.method = function() { + return; + }; this.object = { method: this.method }; }); - it("defines restore method", function () { - wrapMethod(this.object, "method", function () { return; }); + it("defines restore method", function() { + wrapMethod(this.object, "method", function() { + return; + }); assert.isFunction(this.object.method.restore); }); - it("returns wrapper", function () { - var wrapper = wrapMethod(this.object, "method", function () { return; }); + it("returns wrapper", function() { + var wrapper = wrapMethod(this.object, "method", function() { + return; + }); assert.same(this.object.method, wrapper); }); - it("restore brings back original method", function () { - wrapMethod(this.object, "method", function () { return; }); + it("restore brings back original method", function() { + wrapMethod(this.object, "method", function() { + return; + }); this.object.method.restore(); assert.same(this.object.method, this.method); }); }); - describe("wrapped prototype method", function () { - beforeEach(function () { - this.type = function () { return; }; - this.type.prototype.method = function () { return; }; + describe("wrapped prototype method", function() { + beforeEach(function() { + this.type = function() { + return; + }; + this.type.prototype.method = function() { + return; + }; this.object = new this.type(); //eslint-disable-line new-cap }); - it("wrap adds owned property", function () { - var wrapper = wrapMethod(this.object, "method", function () { return; }); + it("wrap adds owned property", function() { + var wrapper = wrapMethod(this.object, "method", function() { + return; + }); assert.same(this.object.method, wrapper); assert(this.object.hasOwnProperty("method")); }); - it("restore removes owned property", function () { - wrapMethod(this.object, "method", function () { return; }); + it("restore removes owned property", function() { + wrapMethod(this.object, "method", function() { + return; + }); this.object.method.restore(); assert.same(this.object.method, this.type.prototype.method); diff --git a/test/util/fake-timers-test.js b/test/util/fake-timers-test.js index 6728ed645..9584ae9f1 100644 --- a/test/util/fake-timers-test.js +++ b/test/util/fake-timers-test.js @@ -9,30 +9,30 @@ var assert = referee.assert; var refute = referee.refute; var GlobalDate = Date; -describe("fakeTimers.clock", function () { - beforeEach(function () { +describe("fakeTimers.clock", function() { + beforeEach(function() { this.global = typeof global !== "undefined" ? global : window; }); - describe(".setTimeout", function () { - beforeEach(function () { + describe(".setTimeout", function() { + beforeEach(function() { this.clock = fakeTimers.clock.create(); this.global.sinonClockEvalCalled = false; }); - afterEach(function () { + afterEach(function() { delete this.global.sinonClockEvalCalled; }); - it("throws if no arguments", function () { + it("throws if no arguments", function() { var clock = this.clock; - assert.exception(function () { + assert.exception(function() { clock.setTimeout(); }); }); - it("returns numeric id or object with numeric id", function () { + it("returns numeric id or object with numeric id", function() { var result = this.clock.setTimeout(""); if (typeof result === "object") { @@ -42,14 +42,14 @@ describe("fakeTimers.clock", function () { } }); - it("returns unique id", function () { + it("returns unique id", function() { var id1 = this.clock.setTimeout(""); var id2 = this.clock.setTimeout(""); refute.equals(id2, id1); }); - it("sets timers on instance", function () { + it("sets timers on instance", function() { var clock1 = fakeTimers.clock.create(); var clock2 = fakeTimers.clock.create(); var stubs = [sinonStub.create(), sinonStub.create()]; @@ -62,16 +62,16 @@ describe("fakeTimers.clock", function () { assert(stubs[1].called); }); - it("evals non-function callbacks", function () { - var evalCalledString = (typeof global !== "undefined" ? "global" : "window") + - ".sinonClockEvalCalled = true"; + it("evals non-function callbacks", function() { + var evalCalledString = + (typeof global !== "undefined" ? "global" : "window") + ".sinonClockEvalCalled = true"; this.clock.setTimeout(evalCalledString, 10); this.clock.tick(10); assert(this.global.sinonClockEvalCalled); }); - it("passes setTimeout parameters", function () { + it("passes setTimeout parameters", function() { var clock = fakeTimers.clock.create(); var stub = sinonStub.create(); @@ -82,10 +82,10 @@ describe("fakeTimers.clock", function () { assert.isTrue(stub.calledWithExactly("the first", "the second")); }); - it("calls correct timeout on recursive tick", function () { + it("calls correct timeout on recursive tick", function() { var clock = fakeTimers.clock.create(); var stub = sinonStub.create(); - var recurseCallback = function () { + var recurseCallback = function() { clock.tick(100); }; @@ -97,13 +97,15 @@ describe("fakeTimers.clock", function () { }); }); - describe(".setImmediate", function () { - beforeEach(function () { + describe(".setImmediate", function() { + beforeEach(function() { this.clock = fakeTimers.clock.create(); }); - it("returns numeric id or object with numeric id", function () { - var result = this.clock.setImmediate(function () { return; }); + it("returns numeric id or object with numeric id", function() { + var result = this.clock.setImmediate(function() { + return; + }); if (typeof result === "object") { assert.isNumber(result.id); @@ -112,7 +114,7 @@ describe("fakeTimers.clock", function () { } }); - it("calls the given callback immediately", function () { + it("calls the given callback immediately", function() { var stub = sinonStub.create(); this.clock.setImmediate(stub); @@ -121,15 +123,15 @@ describe("fakeTimers.clock", function () { assert(stub.called); }); - it("throws if no arguments", function () { + it("throws if no arguments", function() { var clock = this.clock; - assert.exception(function () { + assert.exception(function() { clock.setImmediate(); }); }); - it("manages separate timers per clock instance", function () { + it("manages separate timers per clock instance", function() { var clock1 = fakeTimers.clock.create(); var clock2 = fakeTimers.clock.create(); var stubs = [sinonStub.create(), sinonStub.create()]; @@ -142,7 +144,7 @@ describe("fakeTimers.clock", function () { assert(stubs[1].called); }); - it("passes extra parameters through to the callback", function () { + it("passes extra parameters through to the callback", function() { var stub = sinonStub.create(); this.clock.setImmediate(stub, "value1", 2); @@ -152,12 +154,12 @@ describe("fakeTimers.clock", function () { }); }); - describe(".clearImmediate", function () { - beforeEach(function () { + describe(".clearImmediate", function() { + beforeEach(function() { this.clock = fakeTimers.clock.create(); }); - it("removes immediate callbacks", function () { + it("removes immediate callbacks", function() { var callback = sinonStub.create(); var id = this.clock.setImmediate(callback); @@ -168,16 +170,16 @@ describe("fakeTimers.clock", function () { }); }); - describe(".tick", function () { - beforeEach(function () { + describe(".tick", function() { + beforeEach(function() { this.clock = fakeTimers.useFakeTimers(0); }); - afterEach(function () { + afterEach(function() { this.clock.restore(); }); - it("triggers immediately without specified delay", function () { + it("triggers immediately without specified delay", function() { var stub = sinonStub.create(); this.clock.setTimeout(stub); @@ -186,7 +188,7 @@ describe("fakeTimers.clock", function () { assert(stub.called); }); - it("does not trigger without sufficient delay", function () { + it("does not trigger without sufficient delay", function() { var stub = sinonStub.create(); this.clock.setTimeout(stub, 100); this.clock.tick(10); @@ -194,7 +196,7 @@ describe("fakeTimers.clock", function () { assert.isFalse(stub.called); }); - it("triggers after sufficient delay", function () { + it("triggers after sufficient delay", function() { var stub = sinonStub.create(); this.clock.setTimeout(stub, 100); this.clock.tick(100); @@ -202,7 +204,7 @@ describe("fakeTimers.clock", function () { assert(stub.called); }); - it("triggers simultaneous timers", function () { + it("triggers simultaneous timers", function() { var spies = [sinonSpy(), sinonSpy()]; this.clock.setTimeout(spies[0], 100); this.clock.setTimeout(spies[1], 100); @@ -213,7 +215,7 @@ describe("fakeTimers.clock", function () { assert(spies[1].called); }); - it("triggers multiple simultaneous timers", function () { + it("triggers multiple simultaneous timers", function() { var spies = [sinonSpy(), sinonSpy(), sinonSpy(), sinonSpy()]; this.clock.setTimeout(spies[0], 100); this.clock.setTimeout(spies[1], 100); @@ -228,10 +230,10 @@ describe("fakeTimers.clock", function () { assert(spies[3].called); }); - it("triggers multiple simultaneous timers with zero callAt", function () { + it("triggers multiple simultaneous timers with zero callAt", function() { var test = this; var spies = [ - sinonSpy(function () { + sinonSpy(function() { test.clock.setTimeout(spies[1], 0); }), sinonSpy(), @@ -249,7 +251,7 @@ describe("fakeTimers.clock", function () { assert(spies[2].called); }); - it("waits after setTimeout was called", function () { + it("waits after setTimeout was called", function() { this.clock.tick(100); var stub = sinonStub.create(); this.clock.setTimeout(stub, 150); @@ -260,7 +262,7 @@ describe("fakeTimers.clock", function () { assert(stub.called); }); - it("mini integration test", function () { + it("mini integration test", function() { var stubs = [sinonStub.create(), sinonStub.create(), sinonStub.create()]; this.clock.setTimeout(stubs[0], 100); this.clock.setTimeout(stubs[1], 120); @@ -280,14 +282,14 @@ describe("fakeTimers.clock", function () { assert(stubs[1].called); }); - it("triggers even when some throw", function () { + it("triggers even when some throw", function() { var clock = this.clock; var stubs = [sinonStub.create().throws(), sinonStub.create()]; clock.setTimeout(stubs[0], 100); clock.setTimeout(stubs[1], 120); - assert.exception(function () { + assert.exception(function() { clock.tick(120); }); @@ -295,19 +297,19 @@ describe("fakeTimers.clock", function () { assert(stubs[1].called); }); - it("calls function with global object or null (strict mode) as this", function () { + it("calls function with global object or null (strict mode) as this", function() { var clock = this.clock; var stub = sinonStub.create().throws(); clock.setTimeout(stub, 100); - assert.exception(function () { + assert.exception(function() { clock.tick(100); }); assert(stub.calledOn(this.global) || stub.calledOn(null)); }); - it("triggers in the order scheduled", function () { + it("triggers in the order scheduled", function() { var spies = [sinonSpy.create(), sinonSpy.create()]; this.clock.setTimeout(spies[0], 13); this.clock.setTimeout(spies[1], 11); @@ -317,10 +319,10 @@ describe("fakeTimers.clock", function () { assert(spies[1].calledBefore(spies[0])); }); - it("creates updated Date while ticking", function () { + it("creates updated Date while ticking", function() { var spy = sinonSpy.create(); - this.clock.setInterval(function () { + this.clock.setInterval(function() { spy(new Date().getTime()); }, 10); @@ -339,7 +341,7 @@ describe("fakeTimers.clock", function () { assert(spy.calledWith(100)); }); - it("fires timer in intervals of 13", function () { + it("fires timer in intervals of 13", function() { var spy = sinonSpy.create(); this.clock.setInterval(spy, 13); @@ -348,17 +350,17 @@ describe("fakeTimers.clock", function () { assert.equals(spy.callCount, 38); }); - it("fires timers in correct order", function () { + it("fires timers in correct order", function() { this.timeout(5000); var spy13 = sinonSpy.create(); var spy10 = sinonSpy.create(); - this.clock.setInterval(function () { + this.clock.setInterval(function() { spy13(new Date().getTime()); }, 13); - this.clock.setInterval(function () { + this.clock.setInterval(function() { spy10(new Date().getTime()); }, 10); @@ -374,7 +376,7 @@ describe("fakeTimers.clock", function () { assert(spy10.getCall(4).calledBefore(spy13.getCall(3))); }); - it("triggers timeouts and intervals in the order scheduled", function () { + it("triggers timeouts and intervals in the order scheduled", function() { var spies = [sinonSpy.create(), sinonSpy.create()]; this.clock.setInterval(spies[0], 10); this.clock.setTimeout(spies[1], 50); @@ -386,9 +388,9 @@ describe("fakeTimers.clock", function () { assert.equals(spies[1].callCount, 1); }); - it("does not fire canceled intervals", function () { + it("does not fire canceled intervals", function() { var id; - var callback = sinonSpy(function () { + var callback = sinonSpy(function() { if (callback.callCount === 3) { clearInterval(id); } @@ -400,7 +402,7 @@ describe("fakeTimers.clock", function () { assert.equals(callback.callCount, 3); }); - it("passes 6 seconds", function () { + it("passes 6 seconds", function() { var spy = sinonSpy.create(); this.clock.setInterval(spy, 4000); @@ -409,7 +411,7 @@ describe("fakeTimers.clock", function () { assert.equals(spy.callCount, 2); }); - it("passes 1 minute", function () { + it("passes 1 minute", function() { var spy = sinonSpy.create(); this.clock.setInterval(spy, 6000); @@ -418,7 +420,7 @@ describe("fakeTimers.clock", function () { assert.equals(spy.callCount, 10); }); - it("passes 2 hours, 34 minutes and 12 seconds", function () { + it("passes 2 hours, 34 minutes and 12 seconds", function() { this.timeout(50000); var spy = sinonSpy.create(); @@ -429,55 +431,55 @@ describe("fakeTimers.clock", function () { assert.equals(spy.callCount, 925); }); - it("throws for invalid format", function () { + it("throws for invalid format", function() { var spy = sinonSpy.create(); this.clock.setInterval(spy, 10000); var test = this; - assert.exception(function () { + assert.exception(function() { test.clock.tick("12:02:34:10"); }); assert.equals(spy.callCount, 0); }); - it("throws for invalid minutes", function () { + it("throws for invalid minutes", function() { var spy = sinonSpy.create(); this.clock.setInterval(spy, 10000); var test = this; - assert.exception(function () { + assert.exception(function() { test.clock.tick("67:10"); }); assert.equals(spy.callCount, 0); }); - it("throws for negative minutes", function () { + it("throws for negative minutes", function() { var spy = sinonSpy.create(); this.clock.setInterval(spy, 10000); var test = this; - assert.exception(function () { + assert.exception(function() { test.clock.tick("-7:10"); }); assert.equals(spy.callCount, 0); }); - it("treats missing argument as 0", function () { + it("treats missing argument as 0", function() { this.clock.tick(); assert.equals(this.clock.now, 0); }); - it("fires nested setTimeout calls properly", function () { + it("fires nested setTimeout calls properly", function() { var i = 0; var clock = this.clock; - var callback = function () { + var callback = function() { ++i; - clock.setTimeout(function () { + clock.setTimeout(function() { callback(); }, 100); }; @@ -489,31 +491,31 @@ describe("fakeTimers.clock", function () { assert.equals(i, 11); }); - it("does not silently catch exceptions", function () { + it("does not silently catch exceptions", function() { var clock = this.clock; - clock.setTimeout(function () { + clock.setTimeout(function() { throw new Error("oh no!"); }, 1000); - assert.exception(function () { + assert.exception(function() { clock.tick(1000); }); }); - it("returns the current now value", function () { + it("returns the current now value", function() { var clock = this.clock; var value = clock.tick(200); assert.equals(clock.now, value); }); }); - describe(".clearTimeout", function () { - beforeEach(function () { + describe(".clearTimeout", function() { + beforeEach(function() { this.clock = fakeTimers.clock.create(); }); - it("removes timeout", function () { + it("removes timeout", function() { var stub = sinonStub.create(); var id = this.clock.setTimeout(stub, 50); this.clock.clearTimeout(id); @@ -522,18 +524,18 @@ describe("fakeTimers.clock", function () { assert.isFalse(stub.called); }); - it("ignores null argument", function () { + it("ignores null argument", function() { this.clock.clearTimeout(null); assert(true); // doesn't fail }); }); - describe(".reset", function () { - beforeEach(function () { + describe(".reset", function() { + beforeEach(function() { this.clock = fakeTimers.clock.create(); }); - it("empties timeouts queue", function () { + it("empties timeouts queue", function() { var stub = sinonStub.create(); this.clock.setTimeout(stub); this.clock.reset(); @@ -543,20 +545,20 @@ describe("fakeTimers.clock", function () { }); }); - describe(".setInterval", function () { - beforeEach(function () { + describe(".setInterval", function() { + beforeEach(function() { this.clock = fakeTimers.clock.create(); }); - it("throws if no arguments", function () { + it("throws if no arguments", function() { var clock = this.clock; - assert.exception(function () { + assert.exception(function() { clock.setInterval(); }); }); - it("returns numeric id or object with numeric id", function () { + it("returns numeric id or object with numeric id", function() { var result = this.clock.setInterval(""); if (typeof result === "object") { @@ -566,14 +568,14 @@ describe("fakeTimers.clock", function () { } }); - it("returns unique id", function () { + it("returns unique id", function() { var id1 = this.clock.setInterval(""); var id2 = this.clock.setInterval(""); refute.equals(id2, id1); }); - it("schedules recurring timeout", function () { + it("schedules recurring timeout", function() { var stub = sinonStub.create(); this.clock.setInterval(stub, 10); this.clock.tick(99); @@ -581,10 +583,10 @@ describe("fakeTimers.clock", function () { assert.equals(stub.callCount, 9); }); - it("does not schedule recurring timeout when cleared", function () { + it("does not schedule recurring timeout when cleared", function() { var clock = this.clock; var id; - var stub = sinonSpy.create(function () { + var stub = sinonSpy.create(function() { if (stub.callCount === 3) { clock.clearInterval(id); } @@ -596,7 +598,7 @@ describe("fakeTimers.clock", function () { assert.equals(stub.callCount, 3); }); - it("passes setTimeout parameters", function () { + it("passes setTimeout parameters", function() { var clock = fakeTimers.clock.create(); var stub = sinonStub.create(); @@ -608,39 +610,43 @@ describe("fakeTimers.clock", function () { }); }); - describe(".date", function () { - beforeEach(function () { + describe(".date", function() { + beforeEach(function() { this.now = new GlobalDate().getTime() - 3000; this.clock = fakeTimers.clock.create(this.now); this.Date = this.global.Date; }); - afterEach(function () { + afterEach(function() { this.global.Date = this.Date; }); - it("provides date constructor", function () { + it("provides date constructor", function() { assert.isFunction(this.clock.Date); }); - it("creates real Date objects", function () { + it("creates real Date objects", function() { var date = new this.clock.Date(); assert(Date.prototype.isPrototypeOf(date)); }); - it("creates real Date objects when called as function", function () { + it("creates real Date objects when called as function", function() { var date = this.clock.Date(); assert(Date.prototype.isPrototypeOf(date)); }); - it("creates real Date objects when Date constructor is gone", function () { + it("creates real Date objects when Date constructor is gone", function() { var realDate = new Date(); // eslint-disable-next-line no-global-assign, no-native-reassign - Date = function () { return; }; - this.global.Date = function () { return; }; + Date = function() { + return; + }; + this.global.Date = function() { + return; + }; var date = new this.clock.Date(); @@ -651,19 +657,19 @@ describe("fakeTimers.clock", function () { assert.same(date.constructor.prototype, realDate.constructor.prototype); }); - it("creates Date objects representing clock time", function () { + it("creates Date objects representing clock time", function() { var date = new this.clock.Date(); assert.equals(date.getTime(), new Date(this.now).getTime()); }); - it("returns Date object representing clock time", function () { + it("returns Date object representing clock time", function() { var date = this.clock.Date(); assert.equals(date.getTime(), new Date(this.now).getTime()); }); - it("listens to ticking clock", function () { + it("listens to ticking clock", function() { var date1 = new this.clock.Date(); this.clock.tick(3); var date2 = new this.clock.Date(); @@ -671,159 +677,159 @@ describe("fakeTimers.clock", function () { assert.equals(date2.getTime() - date1.getTime(), 3); }); - it("creates regular date when passing timestamp", function () { + it("creates regular date when passing timestamp", function() { var date = new Date(); var fakeDate = new this.clock.Date(date.getTime()); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with timestamp", function () { + it("returns regular date when calling with timestamp", function() { var date = new Date(); var fakeDate = this.clock.Date(date.getTime()); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("creates regular date when passing year, month", function () { + it("creates regular date when passing year, month", function() { var date = new Date(2010, 4); var fakeDate = new this.clock.Date(2010, 4); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with year, month", function () { + it("returns regular date when calling with year, month", function() { var date = new Date(2010, 4); var fakeDate = this.clock.Date(2010, 4); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("creates regular date when passing y, m, d", function () { + it("creates regular date when passing y, m, d", function() { var date = new Date(2010, 4, 2); var fakeDate = new this.clock.Date(2010, 4, 2); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with y, m, d", function () { + it("returns regular date when calling with y, m, d", function() { var date = new Date(2010, 4, 2); var fakeDate = this.clock.Date(2010, 4, 2); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("creates regular date when passing y, m, d, h", function () { + it("creates regular date when passing y, m, d, h", function() { var date = new Date(2010, 4, 2, 12); var fakeDate = new this.clock.Date(2010, 4, 2, 12); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with y, m, d, h", function () { + it("returns regular date when calling with y, m, d, h", function() { var date = new Date(2010, 4, 2, 12); var fakeDate = this.clock.Date(2010, 4, 2, 12); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("creates regular date when passing y, m, d, h, m", function () { + it("creates regular date when passing y, m, d, h, m", function() { var date = new Date(2010, 4, 2, 12, 42); var fakeDate = new this.clock.Date(2010, 4, 2, 12, 42); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with y, m, d, h, m", function () { + it("returns regular date when calling with y, m, d, h, m", function() { var date = new Date(2010, 4, 2, 12, 42); var fakeDate = this.clock.Date(2010, 4, 2, 12, 42); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("creates regular date when passing y, m, d, h, m, s", function () { + it("creates regular date when passing y, m, d, h, m, s", function() { var date = new Date(2010, 4, 2, 12, 42, 53); var fakeDate = new this.clock.Date(2010, 4, 2, 12, 42, 53); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with y, m, d, h, m, s", function () { + it("returns regular date when calling with y, m, d, h, m, s", function() { var date = new Date(2010, 4, 2, 12, 42, 53); var fakeDate = this.clock.Date(2010, 4, 2, 12, 42, 53); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("creates regular date when passing y, m, d, h, m, s, ms", function () { + it("creates regular date when passing y, m, d, h, m, s, ms", function() { var date = new Date(2010, 4, 2, 12, 42, 53, 498); var fakeDate = new this.clock.Date(2010, 4, 2, 12, 42, 53, 498); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("returns regular date when calling with y, m, d, h, m, s, ms", function () { + it("returns regular date when calling with y, m, d, h, m, s, ms", function() { var date = new Date(2010, 4, 2, 12, 42, 53, 498); var fakeDate = this.clock.Date(2010, 4, 2, 12, 42, 53, 498); assert.equals(fakeDate.getTime(), date.getTime()); }); - it("mirrors native Date.prototype", function () { + it("mirrors native Date.prototype", function() { assert.same(this.clock.Date.prototype, Date.prototype); }); - it("supports now method if present", function () { + it("supports now method if present", function() { assert.same(typeof this.clock.Date.now, typeof Date.now); }); if (Date.now) { - describe(".now", function () { - it("returns clock.now", function () { + describe(".now", function() { + it("returns clock.now", function() { assert.equals(this.clock.Date.now(), this.now); }); }); } else { - describe("unsupported now", function () { - it("is undefined", function () { + describe("unsupported now", function() { + it("is undefined", function() { refute.defined(this.clock.Date.now); }); }); } - it("mirrors parse method", function () { + it("mirrors parse method", function() { assert.same(this.clock.Date.parse, Date.parse); }); - it("mirrors UTC method", function () { + it("mirrors UTC method", function() { assert.same(this.clock.Date.UTC, Date.UTC); }); - it("mirrors toUTCString method", function () { + it("mirrors toUTCString method", function() { assert.same(this.clock.Date.prototype.toUTCString, Date.prototype.toUTCString); }); if (Date.toSource) { - describe(".toSource", function () { - it("is mirrored", function () { + describe(".toSource", function() { + it("is mirrored", function() { assert.same(this.clock.Date.toSource(), Date.toSource()); }); }); } else { - describe("unsupported toSource", function () { - it("is undefined", function () { + describe("unsupported toSource", function() { + it("is undefined", function() { refute.defined(this.clock.Date.toSource); }); }); } - it("mirrors toString", function () { + it("mirrors toString", function() { assert.same(this.clock.Date.toString(), Date.toString()); }); }); - describe(".useFakeTimers", function () { - beforeEach(function () { + describe(".useFakeTimers", function() { + beforeEach(function() { this.dateNow = this.global.Date.now; this.original = { Date: this.global.Date, @@ -836,7 +842,7 @@ describe("fakeTimers.clock", function () { }; }); - afterEach(function () { + afterEach(function() { this.global.Date = this.original.Date; this.global.setTimeout = this.original.setTimeout; this.global.clearTimeout = this.original.clearTimeout; @@ -853,14 +859,14 @@ describe("fakeTimers.clock", function () { } }); - it("returns clock object", function () { + it("returns clock object", function() { this.clock = fakeTimers.useFakeTimers(); assert.isObject(this.clock); assert.isFunction(this.clock.tick); }); - it("has clock property", function () { + it("has clock property", function() { this.clock = fakeTimers.useFakeTimers(); assert.same(setTimeout.clock, this.clock); @@ -870,13 +876,13 @@ describe("fakeTimers.clock", function () { assert.same(Date.clock, this.clock); }); - it("sets initial timestamp", function () { + it("sets initial timestamp", function() { this.clock = fakeTimers.useFakeTimers(1400); assert.equals(this.clock.now, 1400); }); - it("replaces global setTimeout", function () { + it("replaces global setTimeout", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); @@ -886,13 +892,17 @@ describe("fakeTimers.clock", function () { assert(stub.called); }); - it("global fake setTimeout should return id", function () { + it("global fake setTimeout should return id", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); var to = setTimeout(stub, 1000); - if (typeof (setTimeout(function () { return; }, 0)) === "object") { + if ( + typeof setTimeout(function() { + return; + }, 0) === "object" + ) { assert.isNumber(to.id); assert.isFunction(to.ref); assert.isFunction(to.unref); @@ -901,7 +911,7 @@ describe("fakeTimers.clock", function () { } }); - it("replaces global clearTimeout", function () { + it("replaces global clearTimeout", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); @@ -911,7 +921,7 @@ describe("fakeTimers.clock", function () { assert.isFalse(stub.called); }); - it("restores global setTimeout", function () { + it("restores global setTimeout", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); this.clock.restore(); @@ -923,7 +933,7 @@ describe("fakeTimers.clock", function () { assert.same(setTimeout, fakeTimers.timers.setTimeout); }); - it("restores global clearTimeout", function () { + it("restores global clearTimeout", function() { this.clock = fakeTimers.useFakeTimers(); sinonStub.create(); this.clock.restore(); @@ -931,7 +941,7 @@ describe("fakeTimers.clock", function () { assert.same(clearTimeout, fakeTimers.timers.clearTimeout); }); - it("replaces global setInterval", function () { + it("replaces global setInterval", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); @@ -941,7 +951,7 @@ describe("fakeTimers.clock", function () { assert(stub.calledTwice); }); - it("replaces global clearInterval", function () { + it("replaces global clearInterval", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); @@ -951,7 +961,7 @@ describe("fakeTimers.clock", function () { assert.isFalse(stub.called); }); - it("restores global setInterval", function () { + it("restores global setInterval", function() { this.clock = fakeTimers.useFakeTimers(); var stub = sinonStub.create(); this.clock.restore(); @@ -963,7 +973,7 @@ describe("fakeTimers.clock", function () { assert.same(setInterval, fakeTimers.timers.setInterval); }); - it("restores global clearInterval", function () { + it("restores global clearInterval", function() { this.clock = fakeTimers.useFakeTimers(); sinonStub.create(); this.clock.restore(); @@ -973,13 +983,15 @@ describe("fakeTimers.clock", function () { /*eslint-disable no-proto*/ if (Object.__proto__) { - it("deletes global property on restore if it was inherited onto the global object", function () { + it("deletes global property on restore if it was inherited onto the global object", function() { // Give the global object an inherited 'tick' method delete this.global.tick; - this.global.__proto__.tick = function () { return; }; + this.global.__proto__.tick = function() { + return; + }; if (!this.global.hasOwnProperty("tick")) { - this.clock = fakeTimers.useFakeTimers({toFake: ["tick"]}); + this.clock = fakeTimers.useFakeTimers({ toFake: ["tick"] }); assert.isTrue(this.global.hasOwnProperty("tick")); this.clock.restore(); @@ -993,11 +1005,13 @@ describe("fakeTimers.clock", function () { } /*eslint-enable no-proto*/ - it("restores global property on restore if it is present on the global object itself", function () { + it("restores global property on restore if it is present on the global object itself", function() { // Directly give the global object a tick method - this.global.tick = function () { return; }; + this.global.tick = function() { + return; + }; - this.clock = fakeTimers.useFakeTimers({toFake: ["tick"]}); + this.clock = fakeTimers.useFakeTimers({ toFake: ["tick"] }); assert.isTrue(this.global.hasOwnProperty("tick")); this.clock.restore(); @@ -1005,7 +1019,7 @@ describe("fakeTimers.clock", function () { delete this.global.tick; }); - it("fakes Date constructor", function () { + it("fakes Date constructor", function() { this.clock = fakeTimers.useFakeTimers(0); var now = new Date(); @@ -1013,52 +1027,56 @@ describe("fakeTimers.clock", function () { assert.equals(now.getTime(), 0); }); - it("fake Date constructor should mirror Date's properties", function () { + it("fake Date constructor should mirror Date's properties", function() { this.clock = fakeTimers.useFakeTimers(0); assert(Boolean(Date.parse)); assert(Boolean(Date.UTC)); }); - it("decide on Date.now support at call-time when supported", function () { - this.global.Date.now = function () { return; }; + it("decide on Date.now support at call-time when supported", function() { + this.global.Date.now = function() { + return; + }; this.clock = fakeTimers.useFakeTimers(0); assert.equals(typeof Date.now, "function"); }); - it("decide on Date.now support at call-time when unsupported", function () { + it("decide on Date.now support at call-time when unsupported", function() { this.global.Date.now = null; this.clock = fakeTimers.useFakeTimers(0); refute.defined(Date.now); }); - it("mirrors custom Date properties", function () { - var f = function () { return; }; + it("mirrors custom Date properties", function() { + var f = function() { + return; + }; this.global.Date.format = f; fakeTimers.useFakeTimers(); assert.equals(Date.format, f); }); - it("restores Date constructor", function () { + it("restores Date constructor", function() { this.clock = fakeTimers.useFakeTimers(0); this.clock.restore(); assert.same(GlobalDate, fakeTimers.timers.Date); }); - it("fakes provided methods", function () { - this.clock = fakeTimers.useFakeTimers({toFake: ["setTimeout", "Date", "setImmediate"]}); + it("fakes provided methods", function() { + this.clock = fakeTimers.useFakeTimers({ toFake: ["setTimeout", "Date", "setImmediate"] }); refute.same(setTimeout, fakeTimers.timers.setTimeout); refute.same(Date, fakeTimers.timers.Date); refute.same(setImmediate, fakeTimers.timers.setImmediate); }); - it("resets faked methods", function () { - this.clock = fakeTimers.useFakeTimers({toFake: ["setTimeout", "Date", "setImmediate"]}); + it("resets faked methods", function() { + this.clock = fakeTimers.useFakeTimers({ toFake: ["setTimeout", "Date", "setImmediate"] }); this.clock.restore(); assert.same(setTimeout, fakeTimers.timers.setTimeout); @@ -1066,18 +1084,18 @@ describe("fakeTimers.clock", function () { assert.same(setImmediate, fakeTimers.timers.setImmediate); }); - it("does not fake methods not provided", function () { - this.clock = fakeTimers.useFakeTimers({toFake: ["setTimeout", "Date", "setImmediate"]}); + it("does not fake methods not provided", function() { + this.clock = fakeTimers.useFakeTimers({ toFake: ["setTimeout", "Date", "setImmediate"] }); assert.same(clearTimeout, fakeTimers.timers.clearTimeout); assert.same(setInterval, fakeTimers.timers.setInterval); assert.same(clearInterval, fakeTimers.timers.clearInterval); }); - it("installs by default without nextTick", function () { + it("installs by default without nextTick", function() { this.clock = fakeTimers.useFakeTimers(); var called = false; - process.nextTick(function () { + process.nextTick(function() { called = true; }); this.clock.runAll(); @@ -1085,10 +1103,10 @@ describe("fakeTimers.clock", function () { this.clock.restore(); }); - it("installs with nextTick", function () { - this.clock = fakeTimers.useFakeTimers({toFake: ["nextTick"]}); + it("installs with nextTick", function() { + this.clock = fakeTimers.useFakeTimers({ toFake: ["nextTick"] }); var called = false; - process.nextTick(function () { + process.nextTick(function() { called = true; }); this.clock.runAll(); @@ -1096,52 +1114,74 @@ describe("fakeTimers.clock", function () { this.clock.restore(); }); - it("installs clock in advancing mode and triggers setTimeout", function (done) { - this.clock = fakeTimers.useFakeTimers({shouldAdvanceTime: true}); - this.clock.setTimeout(function () { - this.clock.restore(); - done(); - }.bind(this), 10); + it("installs clock in advancing mode and triggers setTimeout", function(done) { + this.clock = fakeTimers.useFakeTimers({ shouldAdvanceTime: true }); + this.clock.setTimeout( + function() { + this.clock.restore(); + done(); + }.bind(this), + 10 + ); }); - it("installs clock in advancing mode and triggers setInterval", function (done) { - this.clock = fakeTimers.useFakeTimers({shouldAdvanceTime: true}); + it("installs clock in advancing mode and triggers setInterval", function(done) { + this.clock = fakeTimers.useFakeTimers({ shouldAdvanceTime: true }); var counter = 0; var iterations = 3; - var id = this.clock.setInterval(function () { - if (counter++ < iterations) {return;} - this.clock.clearInterval(id); - this.clock.restore(); - done(); - }.bind(this), 10); + var id = this.clock.setInterval( + function() { + if (counter++ < iterations) { + return; + } + this.clock.clearInterval(id); + this.clock.restore(); + done(); + }.bind(this), + 10 + ); }); - it("installs clock in advancing mode and triggers setImmediate", function (done) { - this.clock = fakeTimers.useFakeTimers({shouldAdvanceTime: true}); - this.clock.setImmediate(function () { - this.clock.restore(); - done(); - }.bind(this)); + it("installs clock in advancing mode and triggers setImmediate", function(done) { + this.clock = fakeTimers.useFakeTimers({ shouldAdvanceTime: true }); + this.clock.setImmediate( + function() { + this.clock.restore(); + done(); + }.bind(this) + ); }); - it("throws on old useFakeTimers signatures", function () { + it("throws on old useFakeTimers signatures", function() { var expectedError = "useFakeTimers expected epoch or config object. See https://github.com/sinonjs/sinon"; - assert.exception(function () { - fakeTimers.useFakeTimers("setImmediate"); - }, { name: "TypeError", message: expectedError }); - - assert.exception(function () { - fakeTimers.useFakeTimers("setImmediate", "Date"); - }, { name: "TypeError", message: expectedError }); - - assert.exception(function () { - fakeTimers.useFakeTimers(1000, "setImmediate", "Date"); - }, { name: "TypeError", message: expectedError }); - - assert.exception(function () { - fakeTimers.useFakeTimers(new Date(10000000), "setImmediate", "Date"); - }, { name: "TypeError", message: expectedError }); + assert.exception( + function() { + fakeTimers.useFakeTimers("setImmediate"); + }, + { name: "TypeError", message: expectedError } + ); + + assert.exception( + function() { + fakeTimers.useFakeTimers("setImmediate", "Date"); + }, + { name: "TypeError", message: expectedError } + ); + + assert.exception( + function() { + fakeTimers.useFakeTimers(1000, "setImmediate", "Date"); + }, + { name: "TypeError", message: expectedError } + ); + + assert.exception( + function() { + fakeTimers.useFakeTimers(new Date(10000000), "setImmediate", "Date"); + }, + { name: "TypeError", message: expectedError } + ); }); }); }); diff --git a/test/webworker/webworker-script.js b/test/webworker/webworker-script.js index d51bbb2a4..c90d04b0c 100644 --- a/test/webworker/webworker-script.js +++ b/test/webworker/webworker-script.js @@ -6,11 +6,11 @@ if (typeof importScripts !== "undefined") { importScripts("/pkg/sinon.js"); - var mySpy = sinon.spy(function (msg) { + var mySpy = sinon.spy(function(msg) { return "worker received:" + msg; }); - onmessage = function (e) { + onmessage = function(e) { postMessage(mySpy(e.data)); }; } diff --git a/test/webworker/webworker-support-assessment.js b/test/webworker/webworker-support-assessment.js index e6a87678f..802a7e0a2 100644 --- a/test/webworker/webworker-support-assessment.js +++ b/test/webworker/webworker-support-assessment.js @@ -4,13 +4,14 @@ var referee = require("@sinonjs/referee"); var assert = referee.assert; if (typeof Worker !== "undefined") { - describe("WebWorker support", function () { + describe("WebWorker support", function() { var sentMessage = "whatever"; - it("should not crash", function (done) { + it("should not crash", function(done) { var worker = new Worker("/test/webworker/webworker-script.js"); - worker.onmessage = function (msg) { - try { // eslint-disable-line no-restricted-syntax + worker.onmessage = function(msg) { + // eslint-disable-next-line no-restricted-syntax + try { assert.same(msg.data, "worker received:" + sentMessage); done(); } catch (err) { From c7848c94b6f1c964209bf217310fff67de7658f2 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Tue, 9 Oct 2018 08:08:20 +0200 Subject: [PATCH 18/21] Add npm task for prettier --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 01938c7c8..e82796a6b 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "prebuild": "rimraf pkg && npm run check-dependencies", "postbuild": "run-s test-esm-bundle", "prepublishOnly": "npm run build", + "prettier": "prettier lib/**/*.js test/**/*.js", "preversion": "./scripts/preversion.sh", "postversion": "./scripts/postversion.sh" }, From 9be0d4e6507d3c652d1663f8f3a200e6d88874c1 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Tue, 9 Oct 2018 08:18:17 +0200 Subject: [PATCH 19/21] Add Prettier to CONTRIBUTING.md --- CONTRIBUTING.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a6d24259..741717cd1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -81,17 +81,28 @@ Sinon.JS aims at supporting the following runtimes: * Node LTS versions -### Style +### Linting and style -Sinon.JS uses [ESLint](http://eslint.org) to keep consistent style. You probably want to install a plugin for your editor. +Sinon.JS uses [ESLint](http://eslint.org) to keep the codebase free of lint, and uses [Prettier](https://prettier.io) to keep consistent style. -The ESLint test will be run before unit tests in the CI environment, your build will fail if it doesn't pass the style check. +If you are contributing to a Sinon project, you'll probably want to configure your editors ([ESLint](https://eslint.org/docs/user-guide/integrations#editors), [Prettier][https://prettier.io/docs/en/editors.html]) to make editing code a more enjoyable experience. + +The ESLint verification (which includes Prettier) will be run before unit tests in the CI environment. The build will fail if the source code does not pass the style check. + + +You can run the linter locally: ``` $ npm run lint ``` -To ensure consistent reporting of lint warnings, you should use the same version as CI environment (defined in `package.json`) +You can fix a lot lint and style violations automatically: + +``` +$ npm run lint -- --fix +``` + +To ensure consistent reporting of lint warnings, you should use the same versions of ESLint and Prettier as defined in `package.json` (which is what the CI servers use). ### Run the tests From 06b4c16080a01d371065da9a49d4f79f7868a23e Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Wed, 10 Oct 2018 08:18:38 +0200 Subject: [PATCH 20/21] Fix violations for no-useless-concat after running Prettier --- lib/sinon/assert.js | 2 +- test/assert-test.js | 32 +++++++++++------------ test/call-test.js | 8 +++--- test/mock-test.js | 6 ++--- test/stub-test.js | 12 ++++----- test/util/core/iterable-to-string-test.js | 2 +- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/sinon/assert.js b/lib/sinon/assert.js index 5ec323287..d76a0d54c 100644 --- a/lib/sinon/assert.js +++ b/lib/sinon/assert.js @@ -133,7 +133,7 @@ assert = { // If this fails, we'll just fall back to the blank string } - failAssertion(this, "expected " + expected + " to be " + "called in order but were called as " + actual); + failAssertion(this, "expected " + expected + " to be called in order but were called as " + actual); } else { assert.pass("callOrder"); } diff --git a/test/assert-test.js b/test/assert-test.js index 623de5e4f..4ce48f039 100644 --- a/test/assert-test.js +++ b/test/assert-test.js @@ -1214,7 +1214,7 @@ describe("assert", function() { it("assert.called exception message", function() { assert.equals( this.message("called", this.obj.doSomething), - "expected doSomething to have been called at " + "least once but was never called" + "expected doSomething to have been called at least once but was never called" ); }); @@ -1223,7 +1223,7 @@ describe("assert", function() { assert.equals( this.message("notCalled", this.obj.doSomething).replace(/ at.*/g, ""), - "expected doSomething to not have been called " + "but was called once\n doSomething()" + "expected doSomething to not have been called but was called once\n doSomething()" ); }); @@ -1275,7 +1275,7 @@ describe("assert", function() { assert.equals( message, - "expected doSomething, doop, foo to be called in " + "order but were called as doop, doSomething, foo" + "expected doSomething, doop, foo to be called in order but were called as doop, doSomething, foo" ); }); @@ -1295,7 +1295,7 @@ describe("assert", function() { var message = this.message("callOrder", obj.doop, obj.foo); - assert.equals(message, "expected doop, foo to be called in " + "order but were called as foo"); + assert.equals(message, "expected doop, foo to be called in order but were called as foo"); }); it("assert.callOrder with missing last call exception message", function() { @@ -1314,7 +1314,7 @@ describe("assert", function() { var message = this.message("callOrder", obj.doop, obj.foo); - assert.equals(message, "expected doop, foo to be called in " + "order but were called as doop"); + assert.equals(message, "expected doop, foo to be called in order but were called as doop"); }); it("assert.callCount exception message", function() { @@ -1322,7 +1322,7 @@ describe("assert", function() { assert.equals( this.message("callCount", this.obj.doSomething, 3).replace(/ at.*/g, ""), - "expected doSomething to be called thrice but was called " + "once\n doSomething()" + "expected doSomething to be called thrice but was called once\n doSomething()" ); }); @@ -1332,7 +1332,7 @@ describe("assert", function() { assert.equals( this.message("calledOnce", this.obj.doSomething).replace(/ at.*/g, ""), - "expected doSomething to be called once but was called " + "twice\n doSomething()\n doSomething()" + "expected doSomething to be called once but was called twice\n doSomething()\n doSomething()" ); this.obj.doSomething(); @@ -1349,7 +1349,7 @@ describe("assert", function() { assert.equals( this.message("calledTwice", this.obj.doSomething).replace(/ at.*/g, ""), - "expected doSomething to be called twice but was called " + "once\n doSomething()" + "expected doSomething to be called twice but was called once\n doSomething()" ); }); @@ -1734,7 +1734,7 @@ describe("assert", function() { assert.equals( this.message("calledWithExactly", this.obj.doSomething, 1, 3).replace(/ at.*/g, ""), - "expected doSomething to be called with exact arguments \n" + "1\n" + "3\n" + color.red("hey") + "expected doSomething to be called with exact arguments \n1\n3\n" + color.red("hey") ); }); @@ -1761,7 +1761,7 @@ describe("assert", function() { assert.equals( this.message("neverCalledWith", this.obj.doSomething, 1, 2).replace(/ at.*/g, ""), - "expected doSomething to never be called with " + "arguments 1, 2\n doSomething(1, 2, 3)" + "expected doSomething to never be called with arguments 1, 2\n doSomething(1, 2, 3)" ); }); @@ -1770,7 +1770,7 @@ describe("assert", function() { assert.equals( this.message("neverCalledWithMatch", this.obj.doSomething, 1, 2).replace(/ at.*/g, ""), - "expected doSomething to never be called with match " + "1, 2\n doSomething(1, 2, 3)" + "expected doSomething to never be called with match 1, 2\n doSomething(1, 2, 3)" ); }); @@ -1780,7 +1780,7 @@ describe("assert", function() { assert.equals( this.message("threw", this.obj.doSomething).replace(/ at.*/g, ""), - "doSomething did not throw exception\n" + " doSomething(1, 3, hey)\n doSomething(1, 3)" + "doSomething did not throw exception\n doSomething(1, 3, hey)\n doSomething(1, 3)" ); }); @@ -1790,14 +1790,14 @@ describe("assert", function() { assert.equals( this.message("alwaysThrew", this.obj.doSomething).replace(/ at.*/g, ""), - "doSomething did not always throw exception\n" + " doSomething(1, 3, hey)\n doSomething(1, 3)" + "doSomething did not always throw exception\n doSomething(1, 3, hey)\n doSomething(1, 3)" ); }); it("assert.match exception message", function() { assert.equals( this.message("match", { foo: 1 }, [1, 3]), - "expected value to match\n" + " expected = [1, 3]\n" + " actual = { foo: 1 }" + "expected value to match\n expected = [1, 3]\n actual = { foo: 1 }" ); }); }); @@ -1828,7 +1828,7 @@ describe("assert", function() { assert.equals( createExceptionMessage("called", obj[symbol]), - "expected Symbol(Something Symbolic) to have been " + "called at least once but was never called" + "expected Symbol(Something Symbolic) to have been called at least once but was never called" ); }); @@ -1841,7 +1841,7 @@ describe("assert", function() { assert.equals( createExceptionMessage("called", obj[symbol]), - "expected Symbol() to have been " + "called at least once but was never called" + "expected Symbol() to have been called at least once but was never called" ); } ); diff --git a/test/call-test.js b/test/call-test.js index 2277dc4b0..42d1bde89 100644 --- a/test/call-test.js +++ b/test/call-test.js @@ -603,7 +603,7 @@ describe("sinonSpy.call", function() { call.yield(); }, { - message: "somethingAwesome cannot yield since no callback was passed. " + "Received [23, 42]" + message: "somethingAwesome cannot yield since no callback was passed. Received [23, 42]" } ); }); @@ -719,7 +719,7 @@ describe("sinonSpy.call", function() { call.yieldOn(thisObj); }, { - message: "somethingAwesome cannot yield since no callback was passed. " + "Received [23, 42]" + message: "somethingAwesome cannot yield since no callback was passed. Received [23, 42]" } ); }); @@ -1605,7 +1605,7 @@ describe("sinonSpy.call", function() { assert.equals( spy.printf("%C").replace(/ at.*/g, ""), - "\n spy(" + str + ")" + "\n\n spy(" + str + ")" + "\n\n spy(" + str + ")" + "\n spy(" + str + ")\n\n spy(" + str + ")\n\n spy(" + str + ")" ); spy.resetHistory(); @@ -1616,7 +1616,7 @@ describe("sinonSpy.call", function() { assert.equals( spy.printf("%C").replace(/ at.*/g, ""), - "\n spy(test)" + "\n spy(" + str + ")" + "\n\n spy(" + str + ")" + "\n spy(test)\n spy(" + str + ")\n\n spy(" + str + ")" ); }); }); diff --git a/test/mock-test.js b/test/mock-test.js index 8360623d7..f8cf3b8f8 100644 --- a/test/mock-test.js +++ b/test/mock-test.js @@ -921,7 +921,7 @@ describe("sinonMock", function() { object.method(); }, { - message: "Unexpected call: method()\n" + " Expected method(42) thrice (never called)" + message: "Unexpected call: method()\n Expected method(42) thrice (never called)" } ); }); @@ -967,7 +967,7 @@ describe("sinonMock", function() { mock.verify(); }, { - message: "Expected method(42) thrice (never called)\n" + "Expectation met: method(1[, ...]) once" + message: "Expected method(42) thrice (never called)\nExpectation met: method(1[, ...]) once" } ); }); @@ -999,7 +999,7 @@ describe("sinonMock", function() { object.method(); }, { - message: "Unexpected call: method()\n" + " Expectation met: method([...]) at most twice" + message: "Unexpected call: method()\n Expectation met: method([...]) at most twice" } ); }); diff --git a/test/stub-test.js b/test/stub-test.js index b9a42836a..6771324a8 100644 --- a/test/stub-test.js +++ b/test/stub-test.js @@ -1479,7 +1479,7 @@ describe("stub", function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield, but no callback " + "was passed. Received [23, 42]" + message: "somethingAwesome expected to yield, but no callback was passed. Received [23, 42]" } ); }); @@ -1606,7 +1606,7 @@ describe("stub", function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield, but no callback " + "was passed. Received [23, 42]" + message: "somethingAwesome expected to yield, but no callback was passed. Received [23, 42]" } ); }); @@ -1749,7 +1749,7 @@ describe("stub", function() { stub(23, 42); }, { - message: "somethingAwesome expected to yield, but no callback " + "was passed. Received [23, 42]" + message: "somethingAwesome expected to yield, but no callback was passed. Received [23, 42]" } ); }); @@ -1859,7 +1859,7 @@ describe("stub", function() { var stub = createStub().yieldsTo("success"); assert.exception(stub, { - message: "stub expected to yield to 'success', but no object " + "with such a property was passed." + message: "stub expected to yield to 'success', but no object with such a property was passed." }); }); @@ -1870,7 +1870,7 @@ describe("stub", function() { var stub = createStub().yieldsTo(symbol); assert.exception(stub, { - message: "stub expected to yield to 'Symbol()', but no object with " + "such a property was passed." + message: "stub expected to yield to 'Symbol()', but no object with such a property was passed." }); } }); @@ -2030,7 +2030,7 @@ describe("stub", function() { this.stub.yieldsToOn("success", this.fakeContext); assert.exception(this.stub, { - message: "stub expected to yield to 'success', but no object " + "with such a property was passed." + message: "stub expected to yield to 'success', but no object with such a property was passed." }); }); diff --git a/test/util/core/iterable-to-string-test.js b/test/util/core/iterable-to-string-test.js index 61b5cddc6..ce64737ab 100644 --- a/test/util/core/iterable-to-string-test.js +++ b/test/util/core/iterable-to-string-test.js @@ -20,7 +20,7 @@ describe("util/core/iterable-to-string", function() { map.set(true, true); map.set(undefined, undefined); map.set(null, null); - var expected = "[1,1]," + "['one','one']," + "[true,true]," + "[undefined,undefined]," + "[null,null]"; + var expected = "[1,1],['one','one'],[true,true],[undefined,undefined],[null,null]"; assert.equals(iterableToString(map), expected); }); From 2bf1e7e4be71bf32f1bf6b098ea1590f82e54aa0 Mon Sep 17 00:00:00 2001 From: Morgan Roderick Date: Wed, 10 Oct 2018 08:19:02 +0200 Subject: [PATCH 21/21] Use eslint-config-sinon@2.0.0 --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index e15b96060..18732cab6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1727,9 +1727,9 @@ } }, "eslint-config-sinon": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/eslint-config-sinon/-/eslint-config-sinon-1.0.3.tgz", - "integrity": "sha1-6vcFIqGL8yUKuQMcfEPw2LD0Daw=", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-sinon/-/eslint-config-sinon-2.0.0.tgz", + "integrity": "sha512-khlU4VombXlCoYv3ifgJ+K9dSfy00BDxLsxpmY4BndO4qbnyAFzDuKLwGbCRKj8GT8WeXu4jLlW86ziZceGsFw==", "dev": true }, "eslint-plugin-ie11": { diff --git a/package.json b/package.json index e82796a6b..f8ef35a0c 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "dependency-check": "^2.9.1", "eslint": "^5.6.1", "eslint-config-prettier": "^3.1.0", - "eslint-config-sinon": "^1.0.0", + "eslint-config-sinon": "^2.0.0", "eslint-plugin-ie11": "^1.0.0", "eslint-plugin-local-rules": "^0.1.0", "eslint-plugin-mocha": "^4.2.0",