Skip to content

Commit eb85b7b

Browse files
committed
Merge pull request #6381 from cbrwizard/clipboard_event_unit_tests
SyntheticClipboardEvent unit tests
2 parents 7a8c460 + e6e38d0 commit eb85b7b

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright 2016-present, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*
9+
* @emails react-core
10+
*/
11+
12+
'use strict';
13+
14+
var SyntheticClipboardEvent;
15+
16+
describe('SyntheticClipboardEvent', function() {
17+
var createEvent;
18+
19+
beforeEach(function() {
20+
SyntheticClipboardEvent = require('SyntheticClipboardEvent');
21+
createEvent = function(nativeEvent) {
22+
var target = require('getEventTarget')(nativeEvent);
23+
return SyntheticClipboardEvent.getPooled({}, '', nativeEvent, target);
24+
};
25+
});
26+
27+
describe('ClipboardEvent interface', function() {
28+
describe('clipboardData', function() {
29+
describe('when event has clipboardData', function() {
30+
it("returns event's clipboardData", function() {
31+
// Mock clipboardData since native implementation doesn't have a constructor
32+
var clipboardData = jasmine.createSpyObj(
33+
'clipboardData',
34+
['dropEffect', 'effectAllowed', 'files', 'items', 'types']
35+
);
36+
var clipboardEvent = createEvent({clipboardData: clipboardData});
37+
38+
expect(clipboardEvent.clipboardData).toBe(clipboardData);
39+
});
40+
});
41+
});
42+
});
43+
44+
describe('EventInterface', function() {
45+
it('normalizes properties from the Event interface', function() {
46+
var target = document.createElement('div');
47+
var syntheticEvent = createEvent({srcElement: target});
48+
49+
expect(syntheticEvent.target).toBe(target);
50+
expect(syntheticEvent.type).toBe(undefined);
51+
});
52+
53+
it('is able to `preventDefault` and `stopPropagation`', function() {
54+
var nativeEvent = {};
55+
var syntheticEvent = createEvent(nativeEvent);
56+
57+
expect(syntheticEvent.isDefaultPrevented()).toBe(false);
58+
syntheticEvent.preventDefault();
59+
expect(syntheticEvent.isDefaultPrevented()).toBe(true);
60+
61+
expect(syntheticEvent.isPropagationStopped()).toBe(false);
62+
syntheticEvent.stopPropagation();
63+
expect(syntheticEvent.isPropagationStopped()).toBe(true);
64+
});
65+
66+
it('is able to `persist`', function() {
67+
var syntheticEvent = createEvent({});
68+
69+
expect(syntheticEvent.isPersistent()).toBe(false);
70+
syntheticEvent.persist();
71+
expect(syntheticEvent.isPersistent()).toBe(true);
72+
});
73+
});
74+
});

0 commit comments

Comments
 (0)