Skip to content

Instantly share code, notes, and snippets.

@scopevale
Created February 15, 2017 14:50
Show Gist options
  • Save scopevale/328971593eeafca0c11d229fd0989a8b to your computer and use it in GitHub Desktop.
Save scopevale/328971593eeafca0c11d229fd0989a8b to your computer and use it in GitHub Desktop.
jasmine's spyOn() + React.js + ES6
import React from 'react';
import _ from 'lodash';
import PubSub from 'pubsub-js';
class Example extends React.Component{
bar(e){
console.log('Bar called')
}
render() {
return(
<button ref="foo" onClick={this.bar}>Hey</button>
)
}
};
export default Example;
describe('Example Test', function() {
var React = require('react/addons');
var TestUtils = React.addons.TestUtils;
var Example = require('./Example.jsx');
var example;
beforeEach(function() {
spyOn(Example.prototype, 'bar');
example = TestUtils.renderIntoDocument(<Example />);
});
it('should exist', function() {
expect(TestUtils.isCompositeComponent(example)).toBeTruthy();
});
it('should call bar() onClick', function() {
var button = React.findDOMNode(pagination.refs.foo);
TestUtils.Simulate.click(button);
expect( example.bar ).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment