Created
February 15, 2017 14:50
-
-
Save scopevale/328971593eeafca0c11d229fd0989a8b to your computer and use it in GitHub Desktop.
jasmine's spyOn() + React.js + ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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