Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
mocha-given
Advanced tools
Readme
Mocha-given is a mocha interface that helps you write cleaner specs using Given
, When
, Then
and And
.
It is a shameless port of Justin Searls' jasmine-given which is a tribute to Jim Weirich's terrific rspec-given gem.
describe 'assigning stuff to this', ->
Given -> @number = 24
When -> @number++
And -> @number *= 2
Then -> @number == 50
describe 'assigning stuff to variables', ->
subject = null
Given -> subject = []
When -> subject.push('foo')
Then -> subject.length == 1
describe 'Testing deferred', ->
Given -> @t = Date.now()
Then.after 1500, 'so much time has passed', -> Date.now() - @t >= 1500
describe 'Testing async', ->
Given -> @subject = new User()
Then 'save user', (done) -> @subject.save(done);
If you have mocha installed globally you need to install mocha-given globally as well.
$ npm install -g mocha mocha-given
Then you can run your tests by setting the interface of mocha to mocha-given
$ mocha -u mocha-given --compilers coffee:coffee-script -R spec
If you have installed mocha and mocha-given locally
$ npm install mocha-given coffee-script
you have to call the mocha binary directly:
$ ./node_modules/.bin/mocha -u mocha-given --compilers coffee:coffee-script -R spec
To run the mocha-given
tests for developing, it has to be symlinked into the node_modules
folder to enable mocha
to resolve mocha-given
.
Therefore run the script:
$ npm run link
Afterwards mocha
has to be installed with $ npm install mocha
.
Now you can run the tests using $ npm tests
and start contributing.
var Mocha = require('mocha');
var fs = require('fs');
var path = require('path');
// require mocha-given after Mocha is set
require('mocha-given');
// the directory with your tests/specs
var testDir = 'tests';
// First, you need to instantiate a Mocha instance.
var mocha = new Mocha({
ui: 'mocha-given',
reporter: 'spec'
});
// Get test files
fs.readdirSync(testDir).filter(function(file){
// allow javascript and coffescript files
return file.match(/\.(coffee|js)$/);
}).forEach(function(file){
mocha.addFile(
path.join(testDir, file)
);
});
// Now, you can run the tests.
mocha.run(function(failures){
process.on('exit', function () {
process.exit(failures);
});
});
Run from command line (with mocha and mocha-given installed):
$ node runtests.js
Thanks to SinnerSchrader for their support and the time to work on this project.
FAQs
Adds a Given-When-Then DSL to mocha as an alternative style for specs
The npm package mocha-given receives a total of 42 weekly downloads. As such, mocha-given popularity was classified as not popular.
We found that mocha-given 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
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.