karma-jasmine-feature
Karma plugin that use gherkin feature files to describe tests with Jasmine
Any feedback is appreciated !
Usage
Install
karma-jasmine-feature is available as an npm module
Install locally with
npm install karma-jasmine-feature --save-dev
Features
The examples are written with Gherkin language : https://github.com/cucumber/cucumber/wiki/Gherkin
Feature: Calculator addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press add
Then the result should be 120 on the screen
@ignore
Scenario: Add two other numbers
Given I have entered 10 into the calculator
And I have entered 79 into the calculator
When I press add
Then the result should be 89 on the screen
And failed the test
Each Gherkin Feature will become a jasmine describe
And each Scenario will become a it
Some tags will allow you to ignore feature execution : jasmine xdescribe() / xit()
- @ignore - ignore Feature or Scenario
- @ignoreOthers - ignore all other feature / scenario exept those with this tag
Javascript Specs
The plugin will look for each features implementations within karma included files and execute matching steps.
The featureSteps() function host a set of steps that will be available for each feature that match the featureSteps regexp
; ;
given/when/then step can be string or regular expression that match a step in the feature file.
;
Each step is executed on an isolated scope (this) which can hold current scenario state. (reset for each scenario)
You can add test initialize and cleanup :
...
To install :
npm install karma-jasmine-feature --save-dev
Then, reference framework in karma.conf.js (require jasmine framework)
frameworks: ['jasmine', 'jasmine-feature'],
And just include feature files and specs in karma.conf.js
files: [
...
'features/**/*.feature'
...
]
Examples
demo.feature:
Feature: Roman numerals
Background:
Given I have a Roman numerals calculator
Scenario Outline: The calculator should transform simple roman numeral to number
Given I enter '<roman>' in the calculator
When I convert the roman numeral
Then the displayed value is '<number>'
Examples:
| roman | number |
| I | 1 |
| V | 5 |
| X | 10 |
| L | 50 |
| C | 100 |
Scenario: Should add two complex roman numerals
Given I enter 'IX' in the calculator
And I enter 'III' in the calculator
When I press add
Then the displayed value is 'XII'
@ignore
Scenario: Should be ignore
Given A scenario with no js implementation
When I include this scenario
Then Nothing happens
demo.feature-specs.js
{ 'use strict'; ; };
Release Note
- 26/08/2015 : First release
- Karma preprocessor to transform feature file into javascript file
- Karma framework to execute features
- exlude tests with @ignore & @ignoreOthers
- custom api :
- map feature file "Feature" with featureStep(/* regexp that match Feature title + description */)
- map steps with given / when / then (/* regexp to catch parameters */)