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

Added tests for getEventTarget #11528

Closed
wants to merge 3 commits into from
Closed
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
54 changes: 54 additions & 0 deletions packages/react-dom/src/events/__tests__/getEventTarget-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright (c) 2016-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
*/

'use strict';

var getEventTarget = require('../getEventTarget').default;

describe('getEventTarget', () => {
describe('when target is present in nativeEvent', () => {
it('returns target', () => {
var target = document.createElement('div');
expect(getEventTarget({target: target})).toBe(target);
});
});

describe('when srcElement is present in nativeEvent', () => {
it('returns srcElement', () => {
var target = document.createElement('div');
expect(getEventTarget({srcElement: target})).toBe(target);
});
});

describe('when neither target nor srcElement is present in nativeEvent', () => {
it('returns the window object', () => {
expect(getEventTarget({})).toBe(window);
});
});

describe('when correspondingUseElement is present in target in nativeEvent', () => {
it('returns srcElement', () => {
var correspondingUseElement = document.createElement('div');
expect(
getEventTarget({
target: {correspondingUseElement: correspondingUseElement},
}),
).toBe(correspondingUseElement);
});
});

describe('when target is a text node', () => {
it('returns the parent element', () => {
var parent = document.createElement('div');
var child = document.createTextNode('');
parent.appendChild(child);
expect(getEventTarget({target: child})).toBe(parent);
});
});
});