Skip to content

Commit 7acd55c

Browse files
committed
Add grunt build and jasmine tests running. Event stream tests
1 parent 9123444 commit 7acd55c

File tree

5 files changed

+156
-2
lines changed

5 files changed

+156
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
tmp
3+

dist/react-bacon.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ReactBacon=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
1+
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.ReactBacon=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
22
module.exports.BaconMixin = ((function(){
33
'use strict';
44

gruntfile.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = function(grunt) {
2+
grunt.loadNpmTasks('grunt-contrib-jasmine');
3+
grunt.loadNpmTasks('grunt-browserify');
4+
5+
grunt.initConfig({
6+
browserify: {
7+
umd: {
8+
files: {
9+
'dist/react-bacon.js': './src/react-bacon.js'
10+
},
11+
options: {
12+
bundleOptions: {
13+
standalone: 'ReactBacon'
14+
}
15+
}
16+
},
17+
test: {
18+
files: {
19+
'tmp/specs.js': './spec/**/*_spec.js'
20+
},
21+
options: {
22+
alias: ['./src/react-bacon.js:react-bacon'],
23+
transform: ['reactify']
24+
}
25+
}
26+
},
27+
jasmine: {
28+
options: {
29+
specs: ['tmp/specs.js'],
30+
reporter: 'spec'
31+
},
32+
src: ['dist/react-bacon.js']
33+
}
34+
});
35+
36+
grunt.registerTask('spec', ['browserify:test', 'jasmine']);
37+
grunt.registerTask('default', 'spec');
38+
};

package.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,16 @@
1212
"bugs": {
1313
"url": "https://github.com/jamesmacaulay/react-bacon/issues"
1414
},
15-
"homepage": "https://github.com/jamesmacaulay/react-bacon"
15+
"homepage": "https://github.com/jamesmacaulay/react-bacon",
16+
"devDependencies": {
17+
"react": "~0.10.0",
18+
"grunt": "~0.4.4",
19+
"grunt-contrib-jasmine": "~0.6.3",
20+
"browserify": "~3.44.2",
21+
"grunt-browserify": "~2.0.8",
22+
"reactify": "~0.13.1"
23+
},
24+
"dependencies": {
25+
"baconjs": "~0.7.10"
26+
}
1627
}

spec/react-bacon_spec.js

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/** @jsx React.DOM */
2+
3+
var React = require('react/addons');
4+
var Utils = React.addons.TestUtils;
5+
Bacon = require('baconjs');
6+
var BaconMixin = require('react-bacon').BaconMixin;
7+
8+
describe('BaconMixin', function() {
9+
describe('#eventStream', function() {
10+
it('returns the stream for that defined name', function() {
11+
var stream;
12+
var Component = React.createClass({
13+
mixins: [BaconMixin],
14+
componentWillMount: function() {
15+
stream = this.eventStream('clicks');
16+
},
17+
render: function() {
18+
return <div />
19+
}
20+
});
21+
var component = Utils.renderIntoDocument(<Component />);
22+
expect(stream instanceof Bacon.EventStream).toBe(true);
23+
});
24+
25+
it('returns always the same event stream', function() {
26+
var reference, anotherReference;
27+
var Component = React.createClass({
28+
mixins: [BaconMixin],
29+
componentWillMount: function() {
30+
reference = this.eventStream('clicks');
31+
anotherReference = this.eventStream('clicks');
32+
},
33+
render: function() {
34+
return <div />
35+
}
36+
});
37+
var component = Utils.renderIntoDocument(<Component />);
38+
expect(reference).toBe(anotherReference);
39+
});
40+
41+
it('defines a function property with the name of the stream', function() {
42+
var Component = React.createClass({
43+
mixins: [BaconMixin],
44+
componentWillMount: function() {
45+
this.eventStream('clicks');
46+
},
47+
render: function() {
48+
return <div />
49+
}
50+
});
51+
52+
var component = Utils.renderIntoDocument(<Component />);
53+
expect(component.clicks.constructor).toBe(Function);
54+
});
55+
56+
it('that defined function can be used as event handler, and pushes to the stream', function() {
57+
var clickedDiv;
58+
var Component = React.createClass({
59+
mixins: [BaconMixin],
60+
componentWillMount: function() {
61+
this.eventStream('clicks').onValue(function() {
62+
clickedDiv = true;
63+
});
64+
},
65+
render: function() {
66+
return <div onClick={this.clicks}/>
67+
}
68+
});
69+
70+
var component = Utils.renderIntoDocument(<Component />);
71+
var div = Utils.findRenderedDOMComponentWithTag(component, 'div');
72+
Utils.Simulate.click(div);
73+
74+
expect(clickedDiv).toBe(true);
75+
});
76+
77+
it('removes subscribers when the component unmounts', function() {
78+
var stream;
79+
var Component = React.createClass({
80+
mixins: [BaconMixin],
81+
componentWillMount: function() {
82+
stream = this.eventStream('clicks');
83+
stream.onValue(function() {
84+
// Does something
85+
});
86+
},
87+
render: function() {
88+
return <div onClick={this.clicks}/>
89+
}
90+
});
91+
92+
var component = Utils.renderIntoDocument(<Component />);
93+
94+
expect(stream.hasSubscribers()).toBe(true);
95+
96+
var unmounted = React.unmountComponentAtNode(component.getDOMNode().parentNode);
97+
expect(unmounted).toBe(true);
98+
99+
expect(stream.hasSubscribers()).toBe(false);
100+
});
101+
});
102+
});

0 commit comments

Comments
 (0)