Christoph Pojer d363b1f2e2 Update Jest APIs on fbsource
Reviewed By: javache

Differential Revision: D3229435

fb-gh-sync-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
fbshipit-source-id: b0e252d69e1f399a946fca6e98ef62ff44c2ef9c
2016-04-27 19:16:32 -07:00

53 lines
1.6 KiB
JavaScript

/**
* Copyright (c) 2015-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.
*/
'use strict';
jest.disableAutomock();
var flattenStyle = require('flattenStyle');
describe('flattenStyle', () => {
it('should merge style objects', () => {
var style1 = {width: 10};
var style2 = {height: 20};
var flatStyle = flattenStyle([style1, style2]);
expect(flatStyle.width).toBe(10);
expect(flatStyle.height).toBe(20);
});
it('should override style properties', () => {
var style1 = {backgroundColor: '#000', width: 10};
var style2 = {backgroundColor: '#023c69', width: null};
var flatStyle = flattenStyle([style1, style2]);
expect(flatStyle.backgroundColor).toBe('#023c69');
expect(flatStyle.width).toBe(null);
});
it('should overwrite properties with `undefined`', () => {
var style1 = {backgroundColor: '#000'};
var style2 = {backgroundColor: undefined};
var flatStyle = flattenStyle([style1, style2]);
expect(flatStyle.backgroundColor).toBe(undefined);
});
it('should not fail on falsy values', () => {
expect(() => flattenStyle([null, false, undefined])).not.toThrow();
});
it('should recursively flatten arrays', () => {
var style1 = {width: 10};
var style2 = {height: 20};
var style3 = {width: 30};
var flatStyle = flattenStyle([null, [], [style1, style2], style3]);
expect(flatStyle.width).toBe(30);
expect(flatStyle.height).toBe(20);
});
});