Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Readme
Jack is a simple but yet powerful mock framework, that can be used with any testing framework with your Node.js module, or in the browser.
var jack = require('jack');
obj.stub('foo');
obj.mock('foo');
obj.spy('foo');
jack.stub(obj, 'foo');
jack.mock(obj, 'foo');
jack.spy(obj, 'foo');
obj.stub('on').and.return(3);
obj.stub('foo').and.return(3, 4, 5);
obj.stub('on').and.replace(function() {
// do magic here.
});
obj.foo.reset(); // in order to reset the method
obj.stub('foo').and.throw('Message');
obj.mock('on').it.should_be.called.once;
obj.mock('on').it.should_be.called.twice;
obj.mock('on').it.should_be.called.exactly(3).times;
obj.mock('on').it.should_be.called.any.number.of.times;
obj.mock('on').it.should_be.called.at.least(1).times;
obj.mock('on').expect.arguments('foo', 'bar');
You should call reset to check if an expectation is met.
obj.on.reset();
Spies are the same as mocks, but the original behavior of the method is kept.
obj.spy('foo');
var jack = require('jack').noConflict();
var jack = require('jack');
var myObj = jack.extend(myObj);
function Obj() {}
jack.extend(Obj);
$ npm install jack
Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.
For more information view the documentation.
Include chai and jack in your testing environment.
var chai = require('chai')
, jack = require('jack');
chai.use(jack.chai);
var expect = chai.expect;
The jack integration with Chai provides a unique approach to mocks/stubs. Assertions
can be defined before or after the test has taking place. This feature is referred to
as tense
detection and is an experimental feature provided Chai, and works in the same
way has negation. Where the keyword not
will negate a statement, the keyword been
will
indicate that we are asserting how something has already behaved. This feature is only
available in the jack/chai integration. Here is an example:
Given our Foo
object that has a method bar
:
var myfoo = new Foo();
myfoo.stub('bar');
If we wanted to assert how we expect this stub to behave in the future, we can create a new future tense assertion:
expect(myfoo).to.be.called.once;
With this, when we reset our stub with myfoo.bar.reset()
, if that assertion is invalid, the reset
will throw. We can attach as many assertions to the stub as needed, but be aware of conflicts.
If, instead, we prefer to test it after we have finished our work, we can create a past tense assertion:
expect(myfoo).to.have.been.called.once;
In this example, we are asserting after all of the work has been done but before the reset. Chai will look into the internals of the stub and determine if an assertion has passed or not. This behavior is a more native chai approach.
Assert the object is a Jack stub.
expect(myfoo.bar).to.be.stub;
Language chain. Negation passes through.
// past
expect(myfoo.bar).to.have.been.called;
// future
expect(myfoo.bar).to.be.called; // call count > 0
Asserts that a stub has not been called. Essentially,
negation for called
.
expect(myfoo.bar).to.have.been.not_called;
Asserts that stub has been called once.
// past
expect(myfoo.bar).to.have.been.called.once;
// future
expect(myfoo.bar).to.be.called.once;
Asserts that stub has been called twice.
// past
expect(myfoo.bar).to.have.been.called.twice;
// future
expect(myfoo.bar).to.be.called.twice;
Asserts that stub has been called exactly n
times.
// past
expect(myfoo.bar).to.have.been.called.exactly(3);
// future
expect(myfoo.bar).to.be.called.exactly(3);
Asserts that stub has been called a minimum of n
times.
// past
expect(myfoo.bar).to.have.been.called.min(3);
// future
expect(myfoo.bar).to.be.called.min(3);
Asserts that stub has been called a maximum of n
times.
// past
expect(myfoo.bar).to.have.been.called.max(3);
// future
expect(myfoo.bar).to.be.called.max(3);
Chai integration will expanding its assertions to include calledWith
and
other argument assertions in the near future.
$ npm install
$ make test
Please post issues to GitHub Issues.
Tests are written in the BDD styles for the Mocha test runner using the multiple assertion interfaces from Chai. Running tests is simple:
make test
A browser suite is also available at test/browser/index.js
. The same test definitions are used in both contexts.
Interested in contributing? Fork to get started.
MIT License
Copyright (C) 2012 Veselin Todorov and Jake Luer.
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
Mock framework for Node.js and the browser.
The npm package jack receives a total of 5 weekly downloads. As such, jack popularity was classified as not popular.
We found that jack 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.