Skip to content

Instantly share code, notes, and snippets.

it.only('picks up state change after promise', function(done) {
const input = TestUtils.renderIntoDocument(<input onChange={sinon.spy()} />);
const p = new Promise(function(resolve, reject) {
setTimeout(() => {
TestUtils.Simulate.change(React.findDOMNode(input));
resolve(true);
}, 10);
});
p.then(function(result) {
expect(result).to.be.true;
@marr
marr / -
Created July 23, 2015 23:47
const input = TestUtils.renderIntoDocument(<input onChange={sinon.spy()} />);
const p = new Promise(function(resolve, reject) {
TestUtils.Simulate.change(React.findDOMNode(input));
resolve(true);
});
p.then(function(result) {
expect(result).to.be.true;
expect(input.props.onChange).has.been.calledOnce;
}).then(done, done);
@marr
marr / -
Created July 23, 2015 23:49
const input = TestUtils.renderIntoDocument(<input onChange={sinon.spy()} />);
Promise.resolve(true).then(result => {
TestUtils.Simulate.change(React.findDOMNode(input));
return result;
}).then(function(result) {
expect(result).to.be.true;
expect(input.props.onChange).has.been.calledOnce;
}).then(done, done);
@marr
marr / -
Created August 7, 2015 00:18
const requestToPromise = function(requestObject) {
return new Promise(function(resolve, reject) {
requestObject
.end(function(err, res) {
if (err) {
reject(err);
}
else {
resolve(res.body);
}
@marr
marr / -
Created August 7, 2015 00:55
var expect = require('chai').expect;
describe('truthiness', function() {
function falsyFoo(x) {
return !(x && x.foo) || x;
}
it('doesn\'t blow up', function() {
expect(falsyFoo(undefined)).to.be.true;
expect(falsyFoo({ foo: false })).to.be.true;
expect(falsyFoo({ foo: true })).to.be.false;
});
@marr
marr / -
Created August 7, 2015 00:57
https://gist.github.com/aa3bb43eda25880e3773
@marr
marr / gist:655ee1fc9c1f653d82cf
Last active August 29, 2015 14:27
Some interesting reactjs bits
/**
* Perform a heuristic test to determine if an object is "array-like".
*
* A monk asked Joshu, a Zen master, "Has a dog Buddha nature?"
* Joshu replied: "Mu."
*
* This function determines if its argument has "array nature": it returns
* true if the argument is an actual array, an `arguments' object, or an
* HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()).
*
const React = require('react');
const TestUtils = React.addons.TestUtils;
const Checkbox = React.createClass({
render() {
return <input type="checkbox"></input>
}
});
describe('Checkbox', function() {
<VirtualHost *:8081>
<IfModule mod_proxy.c>
ProxyPass / http://127.0.0.1:8080/
ProxyPreserveHost On
</IfModule>
</VirtualHost>
$ sudo gem install bundler
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/bundle