Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mortalflesh/jasmine-data-provider
https://github.com/mortalflesh/jasmine-data-provider
data-provider jasmine
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/mortalflesh/jasmine-data-provider
- Owner: MortalFlesh
- Created: 2015-04-08T21:00:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-09-29T08:22:05.000Z (over 6 years ago)
- Last Synced: 2024-10-14T07:42:34.175Z (3 months ago)
- Topics: data-provider, jasmine
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/jasmine-data-provider
- Size: 3.91 KB
- Stars: 30
- Watchers: 5
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jasmine - data provider
- I am used to use data provider in PHPunit so I have been searching for some solution in jasmine
- but I found only this (https://github.com/jphpsf/jasmine-data-provider), problem is, this is just for jasmine v1.2
- so I updated it
- now you can use Jasmine 2.2.0 and use data providers just like that:## Usage
```javascript
var using = require('jasmine-data-provider');describe('test subtraction with data provider - direct array', function () {
using([{a: 5, b: 2, expected: 3}, {a: 25, b: 26, expected: -1}], function (data) {
it('should calc with operator -', function () {
var result = calculator.calc(data.a, data.b, '-');expect(result).toEqual(data.expected);
});
});
});
```Using function as a data provider
```javascript
describe('test addition with data provider - provider function', function () {
function plusProvider() {
return [
{a: 2, b: 3, expected: 5},
{a: '14', b: 15, expected: 29},
{a: 12, b: '13', expected: 25},
{a: '22', b: '13', expected: 35},
];
}using(plusProvider, function (data) {
it('should calc with operator +', function () {
var result = calculator.calc(data.a, data.b, '+');expect(result).toEqual(data.expected);
});
});
});
```Now you can use object with a description that is passed into to the callback function as the last parameter
```javascript
describe('My fantastic test', function () {
var objectDataProvider = {
'First one is awesome!': {a: 6, b: 3, expected: 9},
'Second test should fail': {a: 8, b: 1, expected: 10}
};using(objectDataProvider, function (data, description) {
it(description, function () {
var result = calculator.calc(data.a, data.b, '+');expect(result).toEqual(data.expected);
});
});
});
```## JS Module Loaders
CommonJS (like browserify), AMD (like requirejs)
## Browser compatibility
Chrome 5+, Firefox 4+, Opera 12+, Safari 5+ and Internet Explorer 9+ (oh yeah..)
## Installation
npm install jasmine-data-provider## Example
https://github.com/MortalFlesh/jasmine