Versatile Dynamic Mocking for NodeJS
Versatile Dynamic Mocking for Node.JS
SuperMock is a very powerful, lightweight, versatile, buzzword, buzzword, mocking library for NodeJS. Influenced by Python's Mock, SuperMock allows you to write mocks with as little setup code as possible.
SuperMock requires harmony-proxies to be enabled
var SuperMock = require'supermock'SuperMockassert = require'assert';//myMock is a function, but also an objectvar myMock = ;myMock'foo' 'bar';//SuperMock keeps track of how many times it has been calledmyMockassertCallCount1;//it also keeps track of what it was called withmyMockassertCalledWith'foo' 'bar';//SuperMock will return a new SuperMock object for everythingmyMockfoobarbazsomething = 42;assertequalmyMockfoobarbazsomething 42;myMockfoobarbazfunc;myMockfoobarbazfuncassertCallCount1;//unless you specify itvar myMock = returnValue:'42' foo:'bar';assertequalmyMock 42;assertequalmyMockfoo 'bar';//Supermock can also throw errorsvar myMock = throws: 'i haz a boo boo' ;assertthrowsmyMock Error;//You can also get the information without having to assertmyMockgetCallCount => 1myMockgetCalledWith =>//you can also access the returnValuevar myMock = ;myMock'123''456''789';myMockassertCalledWith'123';myMockreturnValueassertCalledWith'456';myMockreturnValuereturnValueassertCalledWith'789';
(The MIT License)
Copyright (c) 2012 Russell Bradberry <firstname.lastname@example.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.