react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / syntheticEvents / __tests__ / SyntheticEvent-test.js
81159 views/**1* Copyright 2013-2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @emails react-core9*/1011"use strict";1213var SyntheticEvent;1415describe('SyntheticEvent', function() {16var createEvent;1718beforeEach(function() {19SyntheticEvent = require('SyntheticEvent');2021createEvent = function(nativeEvent) {22return SyntheticEvent.getPooled({}, '', nativeEvent);23};24});2526it('should normalize `target` from the nativeEvent', function() {27var target = document.createElement('div');28var syntheticEvent = createEvent({srcElement: target});2930expect(syntheticEvent.target).toBe(target);31expect(syntheticEvent.type).toBe(undefined);32});3334it('should be able to `preventDefault`', function() {35var nativeEvent = {};36var syntheticEvent = createEvent(nativeEvent);3738expect(syntheticEvent.isDefaultPrevented()).toBe(false);39syntheticEvent.preventDefault();40expect(syntheticEvent.isDefaultPrevented()).toBe(true);4142expect(syntheticEvent.defaultPrevented).toBe(true);4344expect(nativeEvent.returnValue).toBe(false);45});4647it('should be prevented if nativeEvent is prevented', function() {48expect(49createEvent({defaultPrevented: true}).isDefaultPrevented()50).toBe(true);51expect(createEvent({returnValue: false}).isDefaultPrevented()).toBe(true);52});5354it('should be able to `stopPropagation`', function() {55var nativeEvent = {};56var syntheticEvent = createEvent(nativeEvent);5758expect(syntheticEvent.isPropagationStopped()).toBe(false);59syntheticEvent.stopPropagation();60expect(syntheticEvent.isPropagationStopped()).toBe(true);6162expect(nativeEvent.cancelBubble).toBe(true);63});6465it('should be able to `persist`', function() {66var syntheticEvent = createEvent({});6768expect(syntheticEvent.isPersistent()).toBe(false);69syntheticEvent.persist();70expect(syntheticEvent.isPersistent()).toBe(true);71});7273});747576