{"id":15062120,"url":"https://github.com/yoavniran/mocha-stirrer","last_synced_at":"2025-04-10T09:54:53.531Z","repository":{"id":29136876,"uuid":"32666889","full_name":"yoavniran/mocha-stirrer","owner":"yoavniran","description":"Easily mock and set up tests for Mocha and Sinon","archived":false,"fork":false,"pushed_at":"2015-06-27T10:40:07.000Z","size":432,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T08:48:24.829Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yoavniran.png","metadata":{"files":{"readme":"readme.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-22T07:47:23.000Z","updated_at":"2018-06-11T11:09:07.000Z","dependencies_parsed_at":"2022-08-02T21:33:57.622Z","dependency_job_id":null,"html_url":"https://github.com/yoavniran/mocha-stirrer","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fmocha-stirrer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fmocha-stirrer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fmocha-stirrer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fmocha-stirrer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoavniran","download_url":"https://codeload.github.com/yoavniran/mocha-stirrer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247792888,"owners_count":20996900,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T23:30:38.800Z","updated_at":"2025-04-10T09:54:53.511Z","avatar_url":"https://github.com/yoavniran.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Coverage Status](https://coveralls.io/repos/yoavniran/mocha-stirrer/badge.svg?branch=master)](https://coveralls.io/r/yoavniran/mocha-stirrer?branch=master)\n[![Build Status](https://travis-ci.org/yoavniran/mocha-stirrer.svg?branch=master)](https://travis-ci.org/yoavniran/mocha-stirrer)\n[![npm version](https://badge.fury.io/js/mocha-stirrer.svg)](http://badge.fury.io/js/mocha-stirrer)\n[![Dependencies](https://david-dm.org/yoavniran/mocha-stirrer.svg)]((https://david-dm.org/yoavniran/mocha-stirrer))\n[![devDependency Status](https://david-dm.org/yoavniran/mocha-stirrer/dev-status.svg)](https://david-dm.org/yoavniran/mocha-stirrer#info=devDependencies)\n[![Codacy Badge](https://www.codacy.com/project/badge/12374261d28a40a5b05054d5b78c783b)](https://www.codacy.com/app/yoavniran/mocha-stirrer)\n[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/)\n\n* [Introduction](#introSection)\n* [Example](#firstExampleSection)\n* [API](#apiSection)\n* [Require Mocker](#requireMockerSection)\n* [Stirring](#stirringSection)\n\n\u003ca name=\"introSection\" id=\"introSection\"\u003e\n# Mocha Stirrer\n\n\n**_Easily mock and set up tests for Mocha and Sinon then test, then reuse_**\n\nA useful utility for testing with mocha and sinon in a friendlier way that allows you to describe the objects and functions you wish\n to spy/stub/mock. Stirrer gives you a way to declare your setup upfront and re-use it between tests so you can write\n them once and then run every test.\n\nA big benefit of Stirrer is that the set up of mocks is made easier and the cleanup is taken care of for you.\n\nThe aim of this tool is to allow you to write as little as set up code as possible focusing on the test cases themselves.\n\nThe **`RequireMocker`** that is part of this package is a strong tool that can be used on its own\nor as part of the stirrer functionality. Read more about it [below](#requireMockerSection).\n\n\u003e _Mocha Stirrer supports only node.js development currently and will not work in the browser_\n\n___\n\n\u003ca id=\"firstExampleSection\" id=\"firstExampleSection\"/\u003e\n## Example\n\nBelow is an example showing how Stirrer can be used to set up ([grind](#grindSection)) a test and then run a test ([pour](#pourSection))\n using the fakes set up and verification defined:\n\nJump [here](#apiSection) for the full API documentation\n\n```js\n\n\tvar stirrer = require(\"../lib/stirrer\");\n\n\tdescribe(\"use stirrer simple\", function () {\n\n\t    var foo = require(\"./foo\");\n\t    var Bar = require(\"./sub/bar\");\n\t    var fs = require(\"fs\");\n\t    var path = require(\"path\");\n\n\t    var cup = stirrer.grind({\n\t        name: \"TEST #3\",\n\t        stubs: {\n\t            \"barGetStats\": [Bar.prototype, \"getStats\"]\n\t        },\n\t        spies: {\n\t            \"pathJoin\": [path, \"join\"]\n\t        },\n\t        mocks: {\n\t            \"fs\": fs\n\t        },\n\t        before: function (cup) {\n\t            this.stubs.barGetStats.returns(\"stats!\");\n\t            this.mocks.fs.expects(\"readdir\").once().callsArgWithAsync(1, \"oh no!\");\n\t        },\n\t        after: function () {\n\t            expect(this.stubs.barGetStats.calledOnce).to.be.true();\n\t            expect(this.spies.pathJoin.calledOnce).to.be.true();\n\t        }\n\t    });\n\n\t    cup.pour(\"fakes setup should work as defined\", function (done) {\n\n\t        expect(Bar.prototype.getStats).to.equal(this.stubs.barGetStats);\n\n\t        var stats = foo.barStats();\n\t        expect(stats).to.equal(\"stats!\");\n\n\t        var res = foo.wat(\"a\", \"b\");\n\t        expect(res).to.equal(\"a/b\");\n\n\t        foo.fs(function (err) {\n\t            expect(err).to.equal(\"oh no!\");\n\t            done();\n\t        });\n\t    });\n\t});\n\n```\n\n___\n\n\u003ca id=\"apiSection\"/\u003e\n## Stirrer API\n\n\u003ca name=\"grindSection\"/\u003e\n### grind([conf](#stirrerGrindConfParSection), [testFn](#stirrerGrindtestFnParSection))\n\n\u003e Alias: create\n\nCreates a new **[Cup](#cupSection)**  instance.\n\nA cup can be used between tests\n\n\u003ca id=\"stirrerGrindConfParSection\"/\u003e\n_conf_ is an object that configures the cup instance. The following properties can be passed in:\n\n* `name` - (optional) any string that will be used for naming mocha hooks\n\n* `pars` - (optional) object map (key/val) or function that returns an object map. Makes it easy to use values between tests\n\n* `spies` - (optional) object map or function returning an object map. Used to create [sinon spies](http://sinonjs.org/docs/#spies-api),\n\t\t\t\t\teach entry in the object map can be one of the following:\n\n\t1. An array with 2 the first element referencing an object, second is the property name\n\t2. A function to spy\n\t3. A special EMPTY string (_stirrer.EMPTY_) to receive an anonymous spy\n\n* `stubs` - (optional) object map or function returning an object map. Used to create [sinon stubs](http://sinonjs.org/docs/#stubs-api),\n                    each entry in the object map can be one of the following:\n\n\t1. An array with 2 or 3 elements, the first element referencing an object, second is the property name\n                    and the third and optional is a function. See sinon API for details\n\t2. An object to be stubbed by sinon\n\t3. A special EMPTY string (_stirrer.EMPTY_) to receive an empty stub\n\n* `mocks` - (optional) object map or function returning an object map. Used to create [sinon mocks](http://sinonjs.org/docs/#mocks-api),\n\t\t\t\teach entry in the object map should be an object reference\n\n* `delay` - (optional, default: false) When true, cup instance will be created but not set up. meaning non of the fakes\n will be defined. The [brew](#cupStartSection) method must be called in order for setup to occur.\n see the [Stirring section](#stirringSection) for further details on the order of how things are set up and run.\n Note that you shouldn't use delay=true when also passing a test function as fakes wont be initialieed.\n setting `setupImmediate` to true overrides this parameters so delay will be ignored\n\n* `transform` - (optional) function receives the currently assigned parameters to the cup instance (cup.pars). If provided, transform\nwill be run every time the cup setup logic is executed which, unless the setupImmediate flag is set to true, will be during the before\n or beforeEach hook\n\n* `before` - (optional) a function that will be called before ([mocha hooks](http://mochajs.org/#hooks)) tests are run within a describe/context block\nreceives a reference to the cup as the context (this) and a reference to the done callback as a parameter. Very similarly to Mocha, if you define a\nthe parameter Stirrer will assume you need it and you will have to call _done();_ in your method or your test will fail\nwith a timeout error\n\n* `after` - (optional) a function that will be called after ([mocha hooks](http://mochajs.org/#hooks)) tests ran within a describe/context block\nreceives a reference to the cup as the context (this) and a reference to the done callback as a parameter. Very similarly to Mocha, if you define a\nthe parameter Stirrer will assume you need it and you will have to call _done();_ in your method or your test will fail\nwith a timeout error\n\n* `beforeEach` - (optional) a function that will be called before ([mocha hooks](http://mochajs.org/#hooks)) each test within a describe/context block\nreceives a reference to the cup as the context (this) and a reference to the done callback as a parameter. Very similarly to Mocha, if you define a\nthe parameter Stirrer will assume you need it and you will have to call _done();_ in your method or your test will fail\nwith a timeout error\n\n* `afterEach` - (optional) a function that will be called after ([mocha hooks](http://mochajs.org/#hooks)) each test within a describe/context block\nreceives a reference to the cup as the context (this) and a reference to the done callback as a parameter. Very similarly to Mocha, if you define a\nthe parameter Stirrer will assume you need it and you will have to call _done();_ in your method or your test will fail\nwith a timeout error\n\n* `sandbox` - (optional) an object with properties to configure the internal [sinon sandbox](http://sinonjs.org/docs/#sandbox) object Stirrer creates.\n\n* `restirForEach` - (optional, default: false) when set to true the cup will be [restir](#restirSection)-red, as in reset, after every test run ([pour](#pourSection)). Unlike the default behavior that will restir the cup only when exiting the context in which the cup was created or the context in which [brew()](#cupStartSection) was called \n\n* `transformForEach` - (optional, default: false) when set to true determines whether the supplied (pars) transform function\nshould be run as part of a beforeEach hook. When false will run as part of a before hook\n\n* `setupImmediate` - (optional, default: false) makes the stirrer run its set up logic immediately during the execution of the grind method.\nAlso, the setup logic will only be executed once - this is good for a standalone cup that will not be reused between tests.\nIf left as false, the setup will happen during the first before or beforeEach hook prior to a test being executed\n\n* `dontRestir` - (optional, default: false) (see [restir](#restirSection)) will prevent the cup from being \"restirred\" (reset) in the\nafter hook. This means that when the mocha context(describe) finishes, non of the fakes will be restored so you will need to do the restoring manually.\n\n* `requires` - (optional)\n requires is either an array or a function (returning array). Each element in the array should either be:\n\n\t1) string with the path of the module to require\n\t2) an object: {path: \"\", options: {}) - options is optional. options can include a 'parentModule' property which should point to a module that will be used for resolving dependencies' path. see the info [here](#stirrerSetReqParentrSection) for more explanation. (for the rest of the options details see [below](#requireMockerRequireOptions))\n\n\tThis will fake require the modules according to the provided path and make them available on the 'required' property of the cup. \t Additional requires can be passed into the `cup` using its [stir](#cupStirMethodSection) method.\n\n* `befores` - (optional) Can either be a function or an array of functions. The signature of these functions is: fn(next). _next_ is a function that must be called otherwise tests will not run.\nEach of the registered methods will be executed in sequence right before a test(pour) is run.\nAdditional befores can be passed into the `cup` using its [stir](#cupStirMethodSection) method.\nAny registered before functions are removed when the cup is [restirred](#restirSection) (reset)\n\n* `afters` - (optional) Can either be a function or an array of functions. The signature of these functions is: fn(next). _next_ is a function that must be called otherwise tests will not finish running.\nEach of the registered methods will be executed in sequence right after a test(pour) is run.\nAdditional afters can be passed into the `cup` using its [stir](#cupStirMethodSection) method\nAny registered afters functions are removed when the cup is [restirred](#restirSection) (reset)\n\n\n\u003ca id=\"stirrerGrindtestFnParSection\"/\u003e\n_testFn_\n\nA test function to be run immediately with the cup object. Provides a shortcut to calling _pour(...)_ on the cup object.\n\n\u003ca id=\"stirrerSetReqParentrSection\"/\u003e\n### setRequireParent(module)\nSets the parent module that will be used as the parent of the fake require. this is needed for module path resolution the default parent module is the first module that required the stirrer (index) this method is needed in case there are test modules in different folders that use the fake require capability of RequireMocker\n\n\u003ca id=\"restirSection\"/\u003e\n### restir(cup)\n\n\u003e Alias: reset\n\nClears the cup's fakes(spies/stubs/mocks) and restores them using the internal sinon sandbox object.\nAll registered afters/befores are removed together with all references to spies/stubs/mocks and stub aliases.\n\nThe cup's restir method is called internally automatically when the mocha context/describe ends in which the grind method was called or if delay was used,\nfrom the ending context in which [brew](#cupStartSection) was called. See the [Stirring section](#stirringSection) below for a more detailed explanation.\n\n\u003ca id=\"requireSection\"\u003e\n### require(cup, requirePath, options)\n\n* `cup`- the cup instance to use as the sandbox and add the stubs to\n* `requirePath` - the module to require. Use the same path as you would use for a normal require. so relative to the current module\n* `options` - see the options details in the RequireMocker section, [require method details](#requireMockerRequireSection)\n_The default context for the setup methods (if you use them) will be the cup instance. To change it simply pass a different setupContext_\n### RequireMocker\n\nThis is the RequireMocker type discussed below. You can new it up and use it on its own. See the [section](#requireMockerSection) below for details.\n\n### EMPTY\n\nWhen grinding a new cup you can specify what you wish to stub or spy. In case you want an anonymous stub/spy ala \"_**sinon.stub();**_\" you can use this special property as the value of the stub or spy. This way:\n\n```js\n\n\tvar stirrer = require(\"mocha-stirrer\");\n\n\tvar cup = stirrer.grind({\n            stubs: {\n                \"emptyStub\": stirrer.EMPTY //will create an anonymous stub\n            },\n            spies: {\n                \"emptySpy\": stirrer.EMPTY //will create an anonymous spy\n            },\n            before: function () {\n                cup.stubs.emptyStub.returns(\"foo\"); //here we use our anonymous stub\n            }\n\t});\n\n```\n\n___\n\n\u003ca id=\"cupSection\" /\u003e\n## The Cup\n\nA cup is created by calling the [grind](#grindSection) method:\n\n```js\n\n\tvar stirrer = require(\"mocha-stirrer\");\n\n    var cup = stirrer.grind({});\n```\n\n\u003ca id=\"cupStirMethodSection\"/\u003e\n### .prototype.stir(conf)\n\nAdd information to the cup that can be used by following tests. the new information is added on top of any other data\nalready passed using the grind method or previously calling stir.\n\n**conf** - object that can consist of any combination of the following properties:\n\n* `pars` -  object map (key/val) or function that returns an object map\n\n* `befores` - array of methods or a single method to be executed before each test. Each method passed receives a '_next_' function  reference as a parameter which it must call. Failing to call _next()_ will cause timeouts as the flow will not progress\n\n```js\n\n    var cup = stirrer.grind(...);\n\n    cup.stir({\n\t\tbefores: function (next) { //can pass one function or an array of functions\n                 //do something here\n\t\t\t\t//...\n                        next(); //dont forget to call next\n                    }\n\t});\n```\n\n\n\n* `afters` array of methods or a single method to be executed after each test. Each method receives a '_next_' function reference  as a parameter which it must call. Failing to call next() will cause timeouts as the flow will not progress.\n\n* `requires` -   array of elements or a function returning array of elements, each element in the array should either be:\n\n\t* string with the path of the module to require or,\n\t* an object: {path: \"\", options: {}) - options is optional\n\n\n\u003ca id=\"pourSection\"/\u003e\n### .prototype.pour(name, fn, stirData)\n\u003e Alias: test\n\nWraps Mocha's it method and executes it with the added flows for befores/afters\n\n* `name` - (mandatory) name for the test\n* `fn` - (optional) function to be executed as the test\n* `stirData` - (optional) data that is stirred into the cup just before the test fn is executed (**[stir'n pour](#stirnpourSection)™**). The same data that can be stirred by calling the [stir](#cupStirMethodSection) method.\n\n\nthe Pour method mimics Mocha's '_it_' function and supports it's different flavors:\n\n1. [Synchronous](http://mochajs.org/#synchronous-code)\n2. [Asynchronous](http://mochajs.org/#asynchronous-code)\n3. [Pending](http://mochajs.org/#pending-tests)\n4. [Exclusive](http://mochajs.org/#exclusive-tests)\n5. [Inclusive](http://mochajs.org/#inclusive-tests)\n\nHere's a simple example of using pour:\n\n```js\n\n    cup.pour(\"my test\", function(){\n\n        //this === cup - the cup is passed as the context for this function so you can do:\n        // this.pars.myPar or this.stubs.myStub\n    });\n\n```\n\nAs mentioned, everything that you could do with Mocha's '_it_' method you can do with pour so this works:\n\n```js\n\n\tcup.pour.only(\"my test\", function(){\n\t\t//this will make Mocha run your test function exclusively\n\t});\n\n```\n\nIf your test function runs asynchronous code then just like with Mocha, you have the done callback to signal the test is done:\n\n```js\n\n\tcup.pour(\"my test\", function(done){\n\t\t//this will make Mocha run your test function exclusively\n\n\t\tdone(); //make sure to call done so Mocha doesnt timeout\n\t});\n\n```\n\nIf you want to use Mocha's '_it_' on your own you can call pour like this:\n\n```js\n\n\tcup.pour.wrap(\"my test\", function(){\n\t    //now its up to you to use Mocha's it:\n\t\t//still true: this === cup\n\n\t    it(\"this is actually my test now\", function(){\n\t    });\n\t});\n\n```\n\u003ca id=\"stirnpourSection\"/\u003e\n#### stir'n pour™\n\nWhen calling _pour()_ and passing _stirData_ you're essentially shortcutting calling stir and then pour separately. The major distinction being is that when calling _stir_ on its own the data will be stirred into the cup internally by using the Mocha before hook, meaning it wont actually be stirred in at the time of calling stir but rather before the first test (pour) of the context. Remember, the before hook happens only once within a Mocha context(describe). If you wish to use _pour_ multiple times in the same context but with different pars or setup/teardown use **stir'n pour™**. If pars are passed as part of the stirData and if a transform function was supplied during the grind then it will be called on the cup's pars object after merging the new pars data.\n\n\n\u003ca id=\"cupStartSection\"/\u003e\n### .prototype.brew()\n\n\u003e Alias: start\n\nIf delay=true was used when grinding the cup then you will need to manually start the cup by calling this method.\nThis will initialize the cup. A good time to use delay and manual start is when you have the cup grinding code at the top of a module\nor in a shared util class. Then you wouldn't want the cup to be started immediately but rather in the right context/describe.\n\n```js\n\n\t//we may define a cup at the top of our test module with the delay flag, like this:\n\n    var delayedCup = stirrer.grind({\n        name: \"delayed cup test\",\n        delay: true,   //cup will not be started immediately\n        spies: {\n            \"pathSpy\": [path, \"join\"]\n        },\n        stubs: {\n            \"readdirSyncStub\": [fs, \"readdir\"]\n        },\n        pars: {\n            readErr: \"oh no!\"\n        },\n        before: function () {\n            this.stubs.readdirSyncStub.callsArgWithAsync(1, this.pars.readErr);\n        },\n        after: function () {\n            expect(this.spies.pathSpy).to.have.been.called();\n            expect(this.stubs.readdirSyncStub).to.have.been.called();\n        }\n    });\n\n    //then when in the right context we can start the cup, like this:\n\n    describe(\"start causes cup fakes to be initialized on demand\", function () {\n\n        delayedCup.brew(); //on demand start\n\n        delayedCup.pour(\"fakes should not be initialized\", function (done) {\n\n            var result = this.spies.pathSpy(\"a\", \"b\");\n            expect(result).to.equal(\"a/b\");\n\n            this.stubs.readdirSyncStub(\"bla\", function (err) {\n                expect(err).to.equal(delayedCup.pars.readErr);\n                done();\n            });\n        });\n    });\n\n```\n\n\n### .prototype.restir()\n\n\u003e Alias: reset\n\nsee the [restir global method details](#restirSection)\n\n\n\u003ca name=\"cupRequireSection\"/\u003e\n### .prototype.require(reqPath, options)\n\nsee the [require global method details](#requireSection)\n\n\n### .prototype.getStub(name)\n\n* `name`- is the way to identify the stub you wish to get.\n\nNormally, you declare objects to stub using the grind method. The key you use is the name that will be used to store the stub on the cup instance. so if you did:\n\n```js\n\n\tvar cup = stirrer.grind({\n\t\tstubs: {\n\t\t\tmyStub: someObj.someFn\n\t\t}\n\t});\n\n```\n\nthen you will be able to access the stub by using: \n\n```js\n\n\tcup.stubs.myStub.returns(...);\n\n```\n\nHowever, if you used the fake reuqire mechanism by calling require on the cup instance. The dependencies of the module you fake require will also be available on the cup.stubs property. But they will be stored using the fully resolved path which is inconvenient to use at best and most likely different per environment. \nThats where getStub comes in as it lets you use an alias or shortcut to get to the stub you want.\n\nSee the following example, if you had the following structure:\n\n* test.js\n\t* testObjects/\n\t\t* foo.js\n\t\t* sub/\n\t\t\t* bar.js\n\n_testObjects/foo.js_ requires _testObjects/sub/bar.js_. In _test.js_ you fake require _foo.js_ and you wish to set up a stubbed method from _bar.js_. You can easily do this by using the cup's getStub method and passing it \"sub/bar\" or even \"testObjects/sub/bar\". both  of these will return the stubbed bar module.\n\nHere is the above explanation in the form of a code example:\n\n```js\n\n\tdescribe(\"pass requires in grind conf\", function () {\n\n            var cup = stirrer.grind({\n                requires: [\n                    \"./testObjects/foo\" //foo will be fake required\n                ],\n                before: function () {\n                    this.getStub(\"sub/bar\").prototype.useDep.returns(\"this works!\"); //foo depends on bar.js and we get to it and set it upusing alias: \"sub/bar\"\n                }\n            });\n\n            cup.pour(\"fake require should be set up correctly\", function () {\n\n                var foo = cup.required[\"./testObjects/foo\"]; //we can get to foo using the required property\n                expect(foo).to.exist();\n                expect(foo.useSubDep(\"\")).to.equal(\"this works!\"); //stub returns what we told it to return\n            });\n        });\n```\n\n### .prototype.transformPars()\n\nWill run the transform function provided (if it one was provided) during the [grind](#grindSection) on the current cup instance's pars object\n\n### .prototype.getRequired(name)\n\nGet a mock-required module using the path it was required with or the alias that was used when the module was required\n\n### .prototype.name : String\n\nThe name of the instance. can be passed initially to the grind method\n\n### .prototype.sb : Sinon.Sandbox\n\nThe instance of sinon sandbox used by the cup. This enables the cup restir method to restore all fakes created by the cup automatically\n\n### .prototype.pars : Object\n\nAll of the parameters (key/val) passed to the cup either during grinding or using the stir method\n\n### .prototype.spies : Object\n\nThe spies created by the cup. Spies are created according to the map passed to the cup during the grinding\n\n### .prototype.stubs : Object\n\nThe stubs created by the cup. Stubs are created according to the map passed to the cup during the grinding\n\n### .prototype.mocks : Object\n\nThe mocks created by the cup. Mocks are created according to the map passed to the cup during the grinding\n\n### .prototype.required : Object\n\nAll of the modules (key/val) that were fake required (using the [Require Mocker](#requireMockerSection)) by passing requires either during grinding or the stir method.\nThe key used is the same one used to identify the module by its path\n\n```js\n\n\t\t\tcup.stir({\n               requires: [\"./testObjects/foo\"] //define the module to fake require\n            });\n\n            cup.pour(\"should be able to test with my faked module\", function(){\n            \tvar fakeFoo = cup.required[\"./testObjects/foo\"]; //the module is now available using the cup's required property\n\t\t\t});\n\n```\n\n---\n\u003ca id=\"requireMockerSection\" /\u003e\n## Require Mocker\n\nThe Mocker lets you require a module using a simple call and it will stub out all of its dependencies (as best it could).\nThis way you don't need to stub everything yourself but let the magic happen for you.\n\nA typical use of the Mocker is through the [cup.require](#cupRequireSection) method. However,\nit is possible to use it directly by using the _RequireMocker_ property of mocha-stirrer\n\nThe typical mock type for the Mocker is STUB. You can control which type is used using the options passed to the [require](#requireMockerRequireSection) method or by setting the global default using this static method: [setGlobalMockType](#setGlobalMockTypeSection)\n\nHere's an example (taken from this [test module](https://github.com/yoavniran/mocha-stirrer/blob/master/test/RequireMocker.standalone.test.js#L55)) -\n\n```js\n \n\tvar Mocker = require(\"mocha-stirrer\").RequireMocker;\n\n\tvar mocker = new Mocker(sinon);  //pass sinon or a sinon sandbox to the mocker\n\n\tMocker.setGlobalMockType(Mocker.MOCK_TYPES.SPY); //change the global mock type\n\n\tvar foo = mocker.require(\"./testObjects/foo\", {\n                dontMock: [\"fs\"],\n                mockType: {\n                    \"path\": Mocker.MOCK_TYPES.STUB, //define a specific mock type for this module\n                    \"./sub/func\": Mocker.MOCK_TYPES.SPY,\n                    \"./sub/bar\": Mocker.MOCK_TYPES.STUB\n                }\n            });\n\n            expect(foo).to.exist();\n\n            expect(foo.bar()).to.equal(\"foo\");\n            expect(foo.wat(\"a\", \"b\")).to.not.exist(); //wat() uses path module which is stubbed so it returns undefined\n            expect(foo.useSub()).to.not.exist();\n            expect(foo.useSubDep(\"world\")).to.not.exist();\n            expect(foo.useFuncDep()).to.equal(\"foo\");\n            expect(foo.useInstance()).to.equal(\"value\");\n            expect(foo.useConsts()).to.equal(\"i love pizza\");\n            expect(foo.useStatic()).to.not.exist();\n            expect(foo.useConstsObj()).to.equal(\"im 1\");\n\n    var Bar = require(\"./testObjects/sub/bar\");\n\n    expect(Bar.prototype.useDep).to.have.been.calledWith(\"world\");\n\n    mocker.restore(); //make sure to clean up by restoring the stubs\n\n```\n\nYou can define a setup function that will be called with the stubbed object as an argument, then you will be able to define\nbehaviors on its stubs easily.\n\nMocker will stub all of the module's dependencies by default. You can pass a list of modules you don't wish Mocker to stub.\n\nsetup functions\n\t- relative path to the mock-required module or the absolute path\n\n\n\u003ca id=\"requireMockerRequireSection\"/\u003e\n### .prototype.require(parent, requirePath, options)\n\n* `parent` - the parent module that is making the mock require - this is normally the test module\n* `requirePath` - the module to require, relative to the test module (parent)\n* \u003ca id=\"requireMockerRequireOptions\"/\u003e `options` - additional setup options:\n\t* dontMock: an array of paths that are required by the module or by its dependencies to not stub\n\t* mockType: either: \n\t\t* an object map of key = path to a required module and value is one of the values in  RequireMocker.MOCK_TYPES (STUB or SPY)\n\t\tex: {\"./sub/myModule\": RequireMocker.MOCK_TYPES.STUB,\n\t\t\t\t\"../anotherModule\":RequireMocker.MOCK_TYPES.SPY}\n\t\t*  one of the values in RequireMocker.MOCK_TYPES (STUB or SPY)\n\t* setup: object map containing the require path of stubbed dependency and a matching function. the function signature is: fn(stub)\n\t* setupContext: the context to pass into the setup method(s)\n\n### .prototype.restore\n\nwhen called directly, will:\n* restore the stubs created by calls to require\n* remove the stubbed modules from node's module cache\n* clear the internal cache\n\n### .prototype.getStubs\n\nget a collection of the stubs created while modules were mock-required\nreturns Object with the key as the path to the module, the value as the stubbed module exports\n\n### .prototype.getSpies\n\nget a collection of the spies created while modules were mock-required\nreturns Object with the key as the path to the module, the value as the spied module exports\n\n### getGlobalDontMock()\nreturns the array of paths/names used to determine which modules not to mock if they are a dependency to mock-required module\n\n### addGlobalDontMock(name)\nadd a path/name of a module to not not mock if its a dependency of a mock-required module. This method also accepts an array of name/path strings\n\n### removeGlobalDontMock(name)\nremove the path/name of a module registered to not be mocked\n\n### clearGlobalDontMock()\nClear the entire list of modules registered to not be mocked\n\n### getGlobalMockType()\nreturns the currently used value for the mock type (STUB or SPY)\n\n\u003ca id=\"setGlobalMockTypeSection\"/\u003e\n### setGlobalMockType()\n\ndefine the mock type to use when mocking dependencies of mock-required modules\n* mockType (use RequireMocker.MOCK_TYPES)\n\n### Mock_TYPES\nEnum containing: STUB, SPY\n\n---\n\u003ca id=\"stirringSection\"/\u003e\n## Stirring\n\nInternally, the mocha hooks (mainly the `before` hook) are used extensively to set up the fakes and your own befores/afters/etc.\nTo use Mocha-Stirrer successfully you should have a good grip of the order of execution of things in Mocha in conjunction with its hooks...\n\nI created a small gist that shows how hooks in Mocha can be set up and the resulting order of execution at: [https://gist.github.com/yoavniran/ad29e7ecfe57570b18f7]()\n\n\u003e this section isnt complete yet","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoavniran%2Fmocha-stirrer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoavniran%2Fmocha-stirrer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoavniran%2Fmocha-stirrer/lists"}