![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
NodeMock is a very simple to use mocking framework which can be used to mock functions in JavaScript objects. You can create mock a function in a single line.
Besides it's simplicity it supports following features * Does not need an existing object to create the mock * Verify arguments (we check deeply on objects and arrays to check the validity) * Allow a return to be sent * Callbacks can also be executed with providing arguments * Method chaining allows creating mocks super easy
NodeMock does not depend on any third party library and then can be used with any JavaScript environment including * NodeJS * Browser * Rhino
Node JS can be used with any testing framework. And we've used it with Nodeunit and it's a perfect match.
var nodemock = require("nodemock");
var mocked = nodemock.mock("foo").takes(10, [10, 20, 30]).returns(98);
mocked.foo(10, [10, 20, 30]); // this will return 98
mocked.foo(10); //throws execption
var mocked = nodemock.mock("foo").takes(20, function(){}).calls(1, 30, [10, 20]);
mockes.foo(20, function(num, arr) {
console.log(num); //prints 30
console.log(arr); //prints [10, 20]
});
/*
When you invoke foo() nodemock will calls the callback(sits in argument index 1 - as specified)
with the parameters 30 and [10, 20] respectively.
*/
var mocked = require('nodemock').mock('foo');
Creating a object with mock function "foo"
mocked.takes(arg1, args2, ...)
Specify arguments of the function and verify then when calling
mocked.returns(returnValue)
Specify the return value of the function
mocked.calls(callbackPosition, callbackArg1, callbackArg2, ...)
Calls a callback at the arguments in index `callbackPosition`
with the arguments specified above
when using this you've to define a function signature as a callback in the argument list
for a callback at index 2 .takes() function will be as,
`mocked.takes(10, 20, function(){})
The MIT License
Copyright (c) 2011 Arunoda Susiripala
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.
FAQs
Simple Yet Powerful Mocking Framework for NodeJs
The npm package nodemock receives a total of 354 weekly downloads. As such, nodemock popularity was classified as not popular.
We found that nodemock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.