react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / browser / ui / dom / __tests__ / CSSPropertyOperations-test.js
81165 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/*jslint evil: true */1213"use strict";1415var React = require('React');1617describe('CSSPropertyOperations', function() {18var CSSPropertyOperations;1920beforeEach(function() {21require('mock-modules').dumpCache();22CSSPropertyOperations = require('CSSPropertyOperations');23});2425it('should create markup for simple styles', function() {26expect(CSSPropertyOperations.createMarkupForStyles({27backgroundColor: '#3b5998',28display: 'none'29})).toBe('background-color:#3b5998;display:none;');30});3132it('should ignore undefined styles', function() {33expect(CSSPropertyOperations.createMarkupForStyles({34backgroundColor: undefined,35display: 'none'36})).toBe('display:none;');37});3839it('should ignore null styles', function() {40expect(CSSPropertyOperations.createMarkupForStyles({41backgroundColor: null,42display: 'none'43})).toBe('display:none;');44});4546it('should return null for no styles', function() {47expect(CSSPropertyOperations.createMarkupForStyles({48backgroundColor: null,49display: null50})).toBe(null);51});5253it('should automatically append `px` to relevant styles', function() {54expect(CSSPropertyOperations.createMarkupForStyles({55left: 0,56margin: 16,57opacity: 0.5,58padding: '4px'59})).toBe('left:0;margin:16px;opacity:0.5;padding:4px;');60});6162it('should trim values so `px` will be appended correctly', function() {63expect(CSSPropertyOperations.createMarkupForStyles({64margin: '16 ',65opacity: 0.5,66padding: ' 4 '67})).toBe('margin:16px;opacity:0.5;padding:4px;');68});6970it('should not append `px` to styles that might need a number', function() {71var CSSProperty = require('CSSProperty');72var unitlessProperties = Object.keys(CSSProperty.isUnitlessNumber);73unitlessProperties.forEach(function(property) {74var styles = {};75styles[property] = 1;76expect(CSSPropertyOperations.createMarkupForStyles(styles))77.toMatch(/:1;$/);78});79});8081it('should create vendor-prefixed markup correctly', function() {82expect(CSSPropertyOperations.createMarkupForStyles({83msTransition: 'none',84MozTransition: 'none'85})).toBe('-ms-transition:none;-moz-transition:none;');86});8788it('should set style attribute when styles exist', function() {89var styles = {90backgroundColor: '#000',91display: 'none'92};93var div = <div style={styles} />;94var root = document.createElement('div');95div = React.render(div, root);96expect(/style=".*"/.test(root.innerHTML)).toBe(true);97});9899it('should not set style attribute when no styles exist', function() {100var styles = {101backgroundColor: null,102display: null103};104var div = <div style={styles} />;105var root = document.createElement('div');106React.render(div, root);107expect(/style=".*"/.test(root.innerHTML)).toBe(false);108});109110it('should warn when using hyphenated style names', function() {111spyOn(console, 'warn');112113expect(CSSPropertyOperations.createMarkupForStyles({114'background-color': 'crimson'115})).toBe('background-color:crimson;');116117expect(console.warn.argsForCall.length).toBe(1);118expect(console.warn.argsForCall[0][0]).toContain('backgroundColor');119});120121it('should warn when updating hyphenated style names', function() {122spyOn(console, 'warn');123124var root = document.createElement('div');125var styles = {126'-ms-transform': 'translate3d(0, 0, 0)',127'-webkit-transform': 'translate3d(0, 0, 0)'128};129130React.render(<div />, root);131React.render(<div style={styles} />, root);132133expect(console.warn.argsForCall.length).toBe(2);134expect(console.warn.argsForCall[0][0]).toContain('msTransform');135expect(console.warn.argsForCall[1][0]).toContain('WebkitTransform');136});137138});139140141