-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6307 from cbrwizard/getEventCharCode_unit_tests
getEventCharCode unit tests
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/renderers/dom/client/utils/__tests__/getEventCharCode-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* Copyright 2016-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails react-core | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var getEventCharCode = require('getEventCharCode'); | ||
|
||
describe('getEventCharCode', function() { | ||
describe('when charCode is present in nativeEvent', function() { | ||
describe('when charCode is 0 and keyCode is 13', function() { | ||
it('returns 13', function() { | ||
var nativeEvent = new KeyboardEvent( | ||
'keypress', {charCode: 0, keyCode: 13} | ||
); | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(13); | ||
}); | ||
}); | ||
|
||
describe('when charCode is not 0 and/or keyCode is not 13', function() { | ||
describe('when charCode is 32 or bigger', function() { | ||
it('returns charCode', function() { | ||
var nativeEvent = new KeyboardEvent('keypress', {charCode: 32}); | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(32); | ||
}); | ||
}); | ||
|
||
describe('when charCode is smaller than 32', function() { | ||
describe('when charCode is 13', function() { | ||
it('returns 13', function() { | ||
var nativeEvent = new KeyboardEvent('keypress', {charCode: 13}); | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(13); | ||
}); | ||
}); | ||
|
||
describe('when charCode is not 13', function() { | ||
it('returns 0', function() { | ||
var nativeEvent = new KeyboardEvent('keypress', {charCode: 31}); | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(0); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
/** | ||
nativeEvent is represented as a plain object here to ease testing, because | ||
KeyboardEvent's 'charCode' event key cannot be deleted to simulate a missing | ||
charCode key. | ||
*/ | ||
describe('when charCode is not present in nativeEvent', function() { | ||
describe('when keyCode is 32 or bigger', function() { | ||
it('returns keyCode', function() { | ||
var nativeEvent = {'keyCode': 32}; | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(32); | ||
}); | ||
}); | ||
|
||
describe('when keyCode is smaller than 32', function() { | ||
describe('when keyCode is 13', function() { | ||
it('returns 13', function() { | ||
var nativeEvent = {'keyCode': 13}; | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(13); | ||
}); | ||
}); | ||
|
||
describe('when keyCode is not 13', function() { | ||
it('returns 0', function() { | ||
var nativeEvent = {'keyCode': 31}; | ||
|
||
expect(getEventCharCode(nativeEvent)).toBe(0); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |