Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81159 views
1
/**
2
* Copyright 2013-2014, 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 SyntheticEvent;
15
16
describe('SyntheticEvent', function() {
17
var createEvent;
18
19
beforeEach(function() {
20
SyntheticEvent = require('SyntheticEvent');
21
22
createEvent = function(nativeEvent) {
23
return SyntheticEvent.getPooled({}, '', nativeEvent);
24
};
25
});
26
27
it('should normalize `target` from the nativeEvent', function() {
28
var target = document.createElement('div');
29
var syntheticEvent = createEvent({srcElement: target});
30
31
expect(syntheticEvent.target).toBe(target);
32
expect(syntheticEvent.type).toBe(undefined);
33
});
34
35
it('should be able to `preventDefault`', function() {
36
var nativeEvent = {};
37
var syntheticEvent = createEvent(nativeEvent);
38
39
expect(syntheticEvent.isDefaultPrevented()).toBe(false);
40
syntheticEvent.preventDefault();
41
expect(syntheticEvent.isDefaultPrevented()).toBe(true);
42
43
expect(syntheticEvent.defaultPrevented).toBe(true);
44
45
expect(nativeEvent.returnValue).toBe(false);
46
});
47
48
it('should be prevented if nativeEvent is prevented', function() {
49
expect(
50
createEvent({defaultPrevented: true}).isDefaultPrevented()
51
).toBe(true);
52
expect(createEvent({returnValue: false}).isDefaultPrevented()).toBe(true);
53
});
54
55
it('should be able to `stopPropagation`', function() {
56
var nativeEvent = {};
57
var syntheticEvent = createEvent(nativeEvent);
58
59
expect(syntheticEvent.isPropagationStopped()).toBe(false);
60
syntheticEvent.stopPropagation();
61
expect(syntheticEvent.isPropagationStopped()).toBe(true);
62
63
expect(nativeEvent.cancelBubble).toBe(true);
64
});
65
66
it('should be 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
});
75
76