Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #74 from NuCivic/add-jest-tests
Browse files Browse the repository at this point in the history
Use jest framework for testing.
  • Loading branch information
topicus authored Apr 12, 2017
2 parents 25cbadf + 2de2577 commit a4c3804
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"es2015",
"react"
]
}
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
jobs:
build:
docker:
- image: node:7.7.3
working_directory: ~/react-nvd3
steps:
- checkout
- run: mkdir -p ~/react-nvd3/artifacts
- run: npm install
- run: ./node_modules/gulp/bin/gulp.js jest
- store_artifacts:
path: ~/react-nvd3/artifacts
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![react-nvd3 Build Status](https://circleci.com/gh/NuCivic/react-nvd3.svg?style=svg)](https://circleci.com/gh/NuCivic/react-nvd3)

React component for NVD3 re-usable charting library

## Requirements
Expand Down
11 changes: 10 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var rename = require('gulp-rename');
var webpack = require('gulp-webpack');
var concat = require('gulp-concat');
var browserSync = require('browser-sync').create();
var jest = require('gulp-jest').default;

gulp.task('js', function () {
gulp.src('index.js')
Expand All @@ -15,6 +16,14 @@ gulp.task('js', function () {
.pipe(gulp.dest('dist'));
});

gulp.task('jest', function () {
return gulp.src('test').pipe(jest({}));
});

gulp.task('test', function(){
gulp.watch(['./src/*', './examples/**/*.js', './test/*.test.js'], ['jest']);
})

gulp.task('js-watch', ['js'], browserSync.reload);

// use default task to launch Browsersync and watch JS files
Expand All @@ -28,4 +37,4 @@ gulp.task('serve', ['js'], function () {
gulp.watch(['./src/*', './examples/**/*.js'], ['js-watch']);
});

gulp.task('default', ['js']);
gulp.task('default', ['js']);
74 changes: 0 additions & 74 deletions karma.conf.js

This file was deleted.

14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,24 @@
"start": "gulp serve"
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-core": "^6.24.1",
"babel-loader": "^6.2.0",
"babel-plugin-array-includes": "^1.1.1",
"babel-plugin-transform-runtime": "^6.1.18",
"babel-preset-es2015": "^6.1.18",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.1.18",
"babel-preset-stage-0": "^6.1.18",
"babel-runtime": "^5.8.34",
"browser-sync": "^2.8.2",
"chai": "^3.4.1",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-jest": "^1.0.0",
"gulp-rename": "^1.2.2",
"gulp-uglify": "^1.3.0",
"gulp-webpack": "^1.5.0",
"karma": "^0.13.19",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^0.2.2",
"karma-mocha": "^0.2.1",
"mocha": "^2.3.4"
"jest": "^19.0.2",
"jest-cli": "^19.0.2",
"webpack": "^2.3.3"
},
"dependencies": {
"d3": "^3.5.16",
Expand Down
7 changes: 0 additions & 7 deletions test/common.js

This file was deleted.

36 changes: 36 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
includes,
negate
} from '../src/utils.js';

describe("The utils.includes function", () => {
beforeEach(() => {
self.TestData = [ 0, 1, 2, 3];
});
afterEach(() => { });

it('should locate a value if it exists', () => {
expect(includes(self.TestData, 0)).toBe.true;
});

it('should locate a value if it does not exists', () => {
let TestData = [ 0, 1, 2, 3];
expect(includes(self.TestData, 'zero')).toBe.false;
});

it('should Throw if non array is checked', () => {
expect(includes).toThrow(TypeError);
});
});

describe("The utils.negate function", () => {
it('should make a positive producer be a negative producer', () => {
let negator = negate(function(a) {return true;});
expect(negator('a')).toBe.false;
});

it('should make a negative producer be a positive producer', () => {
let negator = negate(function(a) {return false;});
expect(negator('a')).toBe.true;
});
});

0 comments on commit a4c3804

Please sign in to comment.