File tree Expand file tree Collapse file tree 9 files changed +97
-50
lines changed Expand file tree Collapse file tree 9 files changed +97
-50
lines changed Original file line number Diff line number Diff line change 2222 "babel-preset-react" : " ^6.11.1" ,
2323 "babel-preset-stage-1" : " ^6.13.0" ,
2424 "babel-preset-stage-2" : " ^6.13.0" ,
25+ "babel-register" : " ^6.18.0" ,
2526 "babelify" : " ^7.3.0" ,
2627 "brfs" : " ^1.4.3" ,
28+ "chai" : " ^3.5.0" ,
2729 "enzyme" : " ^2.4.1" ,
2830 "eslint" : " ^1.6.0" ,
2931 "eslint-plugin-react" : " ^3.5.1" ,
3032 "gulp" : " ^3.9.0" ,
31- "jest" : " ^14.1.0" ,
3233 "jest-cli" : " ^14.1.0" ,
34+ "jsdom" : " ^9.8.3" ,
3335 "lodash" : " ^4.14.2" ,
36+ "mocha" : " ^3.2.0" ,
3437 "react" : " ^0.14 || ^15.0.0-rc || ^15.0" ,
3538 "react-addons-test-utils" : " ^15.3.1" ,
3639 "react-component-gulp-tasks" : " git+https://github.com/gor181/react-component-gulp-tasks.git" ,
3740 "react-dom" : " ^0.14 || ^15.0.0-rc || ^15.0" ,
3841 "react-notification-system" : " ^0.2.7" ,
3942 "react-redux" : " ^4.4.5" ,
40- "redux" : " ^3.5.2"
43+ "redux" : " ^3.5.2" ,
44+ "sinon" : " ^1.17.6"
4145 },
4246 "dependencies" : {
4347 "react-notification-system" : " ^0.2.7"
5660 "publish:site" : " NODE_ENV=production gulp publish:examples" ,
5761 "release" : " NODE_ENV=production gulp release" ,
5862 "start" : " gulp dev" ,
59- "test" : " jest" ,
63+ "test" : " mocha test/__tests__/**/*" ,
64+ "test-dev" : " mocha test/__tests__/**/* --watch" ,
6065 "watch" : " gulp watch:lib"
6166 },
6267 "keywords" : [
63- " react" ,
64- " react-component"
65- ],
66- "jest" : {
67- "automock" : false
68- }
68+ " react-notification-system" ,
69+ " redux"
70+ ]
6971}
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai' ;
2+ import * as Actions from '../../src/actions' ;
3+
4+ describe ( 'actions' , ( ) => {
5+ it ( 'sets the correct notification level' , ( ) => {
6+ expect ( Actions . success ( ) . level ) . to . equal ( 'success' ) ;
7+ expect ( Actions . warning ( ) . level ) . to . equal ( 'warning' ) ;
8+ expect ( Actions . info ( ) . level ) . to . equal ( 'info' ) ;
9+ expect ( Actions . error ( ) . level ) . to . equal ( 'error' ) ;
10+ } ) ;
11+
12+ it ( 'accepts custom opts' , ( ) => {
13+ expect ( Actions . success ( { custom : true } ) . custom ) . to . be . ok ;
14+ } ) ;
15+
16+ it ( 'generates random uid when not provided' , ( ) => {
17+ expect ( Actions . success ( ) . uid ) . to . be . defined ;
18+ } ) ;
19+
20+ if ( 'sets the custom uid when provided' , ( ) => {
21+ expect ( Actions . success ( { uid : 1 } ) . uid ) . to . equal ( 1 ) ;
22+ } ) ;
23+ } ) ;
Original file line number Diff line number Diff line change 1+ import { expect } from 'chai' ;
2+ import * as Constants from '../../src/const' ;
3+
4+ describe ( 'constants' , ( ) => {
5+ it ( 'should be defined' , ( ) => {
6+ expect ( Constants . RNS_SHOW_NOTIFICATION ) . to . be . defined ;
7+ expect ( Constants . RNS_HIDE_NOTIFICATION ) . to . be . defined ;
8+ } ) ;
9+ } ) ;
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { shallow } from 'enzyme' ;
3- import Component from '../notifications' ;
3+ import { expect } from 'chai' ;
4+ import sinon from 'sinon' ;
5+ import Component from '../../src/notifications' ;
46import NotifySystem from 'react-notification-system' ;
57
68describe ( 'NotificationsComponent' , ( ) => {
79 it ( 'should render one <NotifySystem /> component' , ( ) => {
810 const wrapper = shallow ( < Component /> ) ;
9- expect ( wrapper . children ( ) ) . toBeDefined ( ) ;
11+ expect ( wrapper . children ( ) ) . to . exist ;
1012 } ) ;
1113
1214 it ( 'should warn if prop:notifications is not array' , ( ) => {
13- spyOn ( console , 'error' ) ;
15+ const c = sinon . stub ( console , 'error' ) ;
1416
1517 const wrapper = shallow ( < Component notifications = { 1 } /> ) ;
16- const warning = console . error . calls . argsFor ( 0 ) [ 0 ] ;
18+ const warning = c . args [ 0 ] [ 0 ] ;
1719
18- expect ( warning ) . toMatch ( / I n v a l i d p r o p ` n o t i f i c a t i o n s ` o f t y p e ` n u m b e r ` s u p p l i e d t o ` N o t i f i c a t i o n s ` , e x p e c t e d ` a r r a y ` ./ ) ;
20+ expect ( warning ) . to . match ( / I n v a l i d p r o p ` n o t i f i c a t i o n s ` o f t y p e ` n u m b e r ` s u p p l i e d t o ` N o t i f i c a t i o n s ` , e x p e c t e d ` a r r a y ` ./ ) ;
21+
22+ c . restore ( ) ;
1923 } ) ;
2024} ) ;
Original file line number Diff line number Diff line change 1- import Reducer from '../reducer' ;
2- import * as Actions from '../actions' ;
1+ import { expect } from 'chai' ;
2+
3+ import Reducer from '../../src/reducer' ;
4+ import * as Actions from '../../src/actions' ;
35
46describe ( 'reducer' , ( ) => {
57 it ( 'initializes state with an array' , ( ) => {
6- expect ( Reducer ( ) ) . toEqual ( [ ] ) ;
8+ expect ( Reducer ( ) ) . to . deep . equal ( [ ] ) ;
79 } ) ;
810
911 it ( 'stores the notification to state' , ( ) => {
1012 const action = Actions . success ( ) ;
1113 const state = Reducer ( [ ] , action ) ;
1214
13- expect ( state . length ) . toEqual ( 1 ) ;
15+ expect ( state . length ) . to . equal ( 1 ) ;
1416 } ) ;
1517
1618 it ( 'stores and removes notification' , ( ) => {
1719 const uid = 1 ;
1820
1921 const state = Reducer ( [ ] , Actions . success ( { uid } ) ) ;
20- expect ( state . length ) . toEqual ( 1 ) ;
22+ expect ( state . length ) . to . equal ( 1 ) ;
2123
2224 const newState = Reducer ( state , Actions . hide ( uid ) ) ;
23- expect ( newState . length ) . toEqual ( 0 ) ;
25+ expect ( newState . length ) . to . equal ( 0 ) ;
2426 } ) ;
2527} ) ;
Original file line number Diff line number Diff line change 1+ --compilers js:babel-register
2+ --require test/utils/dom.js
3+ --reporter spec
Original file line number Diff line number Diff line change 1+ const jsdom = require ( 'jsdom' ) ;
2+
3+ // setup the simplest document possible
4+ const doc = jsdom . jsdom ( '<!doctype html><html><body></body></html>' ) ;
5+
6+ // get the window object out of the document
7+ const win = doc . defaultView ;
8+
9+ // set globals for mocha that make access to document and window feel
10+ // natural in the test environment
11+ global . document = doc ;
12+ global . window = win ;
13+
14+ //JSDOM doesn't support localStrage by default, so lets just fake it..
15+ if ( ! global . window . localStorage ) {
16+ global . window . localStorage = {
17+ getItem ( ) { return '{}' ; } ,
18+ setItem ( ) { }
19+ } ;
20+ }
21+
22+ // take all properties of the window object and also attach it to the
23+ // mocha global object
24+ propagateToGlobal ( win ) ;
25+
26+ // from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
27+ function propagateToGlobal ( window ) {
28+ for ( let key in window ) {
29+ if ( ! window . hasOwnProperty ( key ) ) continue ;
30+ if ( key in global ) continue ;
31+
32+ global [ key ] = window [ key ] ;
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments