Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TestUtils] Implement type property in Simulate.<eventName> #6154

Merged
merged 1 commit into from
Jun 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/test/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ function makeSimulator(eventType) {

var fakeNativeEvent = new Event();
fakeNativeEvent.target = node;
fakeNativeEvent.type = eventType.toLowerCase();

// We don't use SyntheticEvent.getPooled in order to not have to worry about
// properly destroying any properties assigned from `eventData` upon release
var event = new SyntheticEvent(
Expand Down
19 changes: 19 additions & 0 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,4 +486,23 @@ describe('ReactTestUtils', function() {
expect(hrs.length).toBe(2);
});

describe('Simulate', () => {
it('should set the type of the event', () => {
let event;
const stub = jest.genMockFn().mockImpl((e) => {
e.persist();
event = e;
});

const container = document.createElement('div');
const instance = ReactDOM.render(<div onKeyDown={stub} />, container);
const node = ReactDOM.findDOMNode(instance);

ReactTestUtils.Simulate.keyDown(node);

expect(event.type).toBe('keydown');
expect(event.nativeEvent.type).toBe('keydown');
});
});

});