Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a

Package Overview
Dependencies
Maintainers
2
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a

Mocking framework and tdd in compact when-style. With recursive test runner

  • 0.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.2K
decreased by-70.84%
Maintainers
2
Weekly downloads
 
Created
Source

A

A is a nodejs module which consists of A mocking framework and A testing framework.

A Mocking framework

Mocking a function

partial mock


var original = function() {
	return 'realValue';
}

var mock = require('a').mock;
original = mock(original);
mock.expect().return('fake');

original(); //returns 'fake'
original(); //returns 'realValue'

strict mock


var original = function() {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expect().return('fake');

original(); //returns 'fake'
original(); //throws unexpected arguments

strict mock with arguments


var original = function(arg) {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expect('testValue1').return('fake1');
mock.expect('testValue2').return('fake2');

original('testValue1'); //returns 'fake1'
original('testValue2'); //returns 'fake2'
original(); //throws unexpected arguments
original('foo'); //throws unexpected arguments

strict mock with multiple arguments


var original = function(arg1, arg2) {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expect('firstArg1', 'secondArg1').return('fake1');
mock.expect('firstArg2', 'secondArg2').return('fake2');


original('firstArg1', 'secondArg1'); //returns 'fake1'
original('firstArg2', 'secondArg2'); //returns 'fake2'
original('foo'); //throws unexpected arguments
original('foo', 'bar'); //throws unexpected arguments

strict mock with repeats


var original = function() {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expect().return('fake').repeat(2);

original(); //returns 'fake'
original(); //returns 'fake'
original(); //throws unexpected arguments

strict mock ignoring arguments


var original = function(arg) {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expectAnything().return('fake1');

original('someRandomValue'); //returns 'fake1'
original(); //throws unexpected arguments

strict mock with interceptor


var original = function(arg) {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expect('testValue').whenCalled(onCalled).return('fake1');

function onCalled(arg) {
	//arg == 'testValue'
}

original('someRandomValue'); //returns 'fake1'
original(); //throws unexpected arguments

strict mock - advanced scenario


var original = function(arg, callback) {
	return 'realValue';
}

var mock = require('a').mock;
original = mock();
mock.expect('testValue').expectAnything().whenCalled(onCalled).return('fake1');

function onCalled(arg,callback) {
	//arg == 'testValue'
	//callback == foo
}

function foo() {	
}


original('testValue', foo); //returns 'fake1'
original('testValue',foo); //throws unexpected arguments

A Testing framework

Keywords

FAQs

Package last updated on 26 Sep 2012

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc