2.2.0 • Published 3 years ago

yadda v2.2.0

Weekly downloads
2,720
License
Apache-2.0
Repository
github
Last release
3 years ago

Yadda

Gitter NPM version NPM downloads Node.js CI Code Climate Test Coverage Code Style

Jasmine, Mocha and Vows can fall out of date and are a form of duplication. Yadda brings true BDD to JavaScript frameworks such as Jasmine, Mocha, QUnit, Nodeunit, WebdriverIO and CasperJS. By true BDD we mean that the ordinary language (e.g. English) steps are mapped to code, as opposed to simply decorating it. This is important because just like comments, the decorative steps such as those used by

Yadda's BDD implementation is like Cucumber's in that it maps the ordinary language steps to code. Not only are the steps less likely to go stale, but they also provide a valuable abstraction layer and encourage re-use. You could of course just use CucumberJS, but we find Yadda less invasive and prefer it's flexible syntax to Gherkin's. Yadda's conflict resolution is smarter too.

Latest Version

The current version of Yadda is 2.2.0

Documentation

Please refer to the the Yadda User Guide.

tl;dr

Step 1 - Decide upon a directory structure, e.g.

.
├── bottles-test.js
├── lib
│    └── wall.js
└── test
    ├── features
    │   └── bottles.feature
    └── steps
        └── bottles-library.js

Step 2 - Write your first scenario

./test/features/bottles.feature

Feature: 100 Green Bottles

Scenario: Should fall from the wall

   Given 100 green bottles are standing on the wall
   When 1 green bottle accidentally falls
   Then there are 99 green bottles standing on the wall

Step 3 - Implement the step library

./test/steps/bottles-library.js

var assert = require('assert');
var English = require('yadda').localisation.English;
var Wall = require('../../lib/wall'); // The library that you wish to test

module.exports = (function () {
  return English.library()
    .given('$NUM green bottles are standing on the wall', function (number, next) {
      wall = new Wall(number);
      next();
    })
    .when('$NUM green bottle accidentally falls', function (number, next) {
      wall.fall(number);
      next();
    })
    .then('there are $NUM green bottles standing on the wall', function (number, next) {
      assert.equal(number, wall.bottles);
      next();
    });
})();

(If your test runner & code are synchronous you can omit the calls to 'next')

Step 4 - Integrate Yadda with your testing framework (e.g. Mocha)

./bottles-test.js

var Yadda = require('yadda');
Yadda.plugins.mocha.StepLevelPlugin.init();

new Yadda.FeatureFileSearch('./test/features').each(function (file) {
  featureFile(file, function (feature) {
    var library = require('./test/steps/bottles-library');
    var yadda = Yadda.createInstance(library);

    scenarios(feature.scenarios, function (scenario) {
      steps(scenario.steps, function (step, done) {
        yadda.run(step, done);
      });
    });
  });
});

Step 5 - Write your code

./lib/wall.js

module.exports = function (bottles) {
  this.bottles = bottles;
  this.fall = function (n) {
    this.bottles -= n;
  };
};

Step 6 - Run your tests

  mocha --reporter spec bottles-test.js

  100 Green Bottles
    Should fall from the wall
      ✓ Given 100 green bottles are standing on the wall
      ✓ When 1 green bottle accidentally falls
      ✓ Then there are 99 green bottles standing on the wall
2.2.0

3 years ago

2.1.1

3 years ago

2.1.0

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.1

7 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.22.1

8 years ago

0.22.0

8 years ago

0.21.0

8 years ago

0.20.0

8 years ago

0.19.0

8 years ago

0.18.0

8 years ago

0.17.10

9 years ago

0.17.9

9 years ago

0.17.8

9 years ago

0.17.7

9 years ago

0.17.6

9 years ago

0.17.5

9 years ago

0.17.4

9 years ago

0.17.3

9 years ago

0.17.2

9 years ago

0.17.1

9 years ago

0.17.0

9 years ago

0.16.3

9 years ago

0.16.2

9 years ago

0.16.1

9 years ago

0.16.0

9 years ago

0.15.5

9 years ago

0.15.4

9 years ago

0.15.3

9 years ago

0.15.2

9 years ago

0.15.1

9 years ago

0.15.0

9 years ago

0.14.1

9 years ago

0.14.0

9 years ago

0.13.1

9 years ago

0.13.0

9 years ago

0.12.1

9 years ago

0.12.0

9 years ago

0.11.7

9 years ago

0.11.6

10 years ago

0.11.5

10 years ago

0.11.4

10 years ago

0.11.3

10 years ago

0.11.2

10 years ago

0.11.1

10 years ago

0.11.0

10 years ago

0.10.14

10 years ago

0.10.13

11 years ago

0.10.12

11 years ago

0.10.11

11 years ago

0.10.10

11 years ago

0.10.9

11 years ago

0.10.8

11 years ago

0.10.7

11 years ago

0.10.6

11 years ago

0.10.5

11 years ago

0.10.4

11 years ago

0.10.3

11 years ago

0.10.1

11 years ago

0.10.0

11 years ago

0.9.11

11 years ago

0.9.10

11 years ago

0.9.9

11 years ago

0.9.8

11 years ago

0.9.7

11 years ago

0.9.6

11 years ago

0.9.5

11 years ago

0.9.4

11 years ago

0.9.3

11 years ago

0.9.2

11 years ago

0.9.1

11 years ago

0.9.0

11 years ago

0.8.6

11 years ago

0.8.5

11 years ago

0.8.4

11 years ago

0.8.3

11 years ago

0.8.2

11 years ago

0.8.1

11 years ago

0.8.0

11 years ago

0.7.2

11 years ago

0.7.1

11 years ago

0.7.0

11 years ago

0.6.5

11 years ago

0.6.4

11 years ago

0.6.3

11 years ago

0.6.2

11 years ago

0.6.1

11 years ago

0.6.0

11 years ago

0.5.2

11 years ago

0.5.1

11 years ago

0.5.0

11 years ago

0.4.7

11 years ago

0.4.6

11 years ago

0.4.5

11 years ago

0.4.4

12 years ago

0.4.3

12 years ago

0.4.2

12 years ago

0.4.1

12 years ago

0.4.0

12 years ago

0.3.0

12 years ago