UNPKG

@ray-core/runtime

Version:

Ray 是一个全新的基于 React 的小程序开发框架

99 lines (98 loc) 6.09 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var diffProperties_1 = __importDefault(require("../../hostConfig/diffProperties")); describe('diffProperties', function () { it('compare props correctly', function () { process.env.NODE_ENV = 'development'; expect(!!(0, diffProperties_1.default)(null, undefined)).toBeFalsy(); expect(!!(0, diffProperties_1.default)(null, null)).toBeFalsy(); expect(!!(0, diffProperties_1.default)(undefined, null)).toBeFalsy(); expect(!!(0, diffProperties_1.default)(undefined, undefined)).toBeFalsy(); expect(!!(0, diffProperties_1.default)(null, {})).toBeFalsy(); expect(!!(0, diffProperties_1.default)({}, null)).toBeFalsy(); expect(!!(0, diffProperties_1.default)(undefined, {})).toBeFalsy(); expect(!!(0, diffProperties_1.default)({}, undefined)).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ k: 'v' }, {})).toBeTruthy(); expect(!!(0, diffProperties_1.default)({}, { k: 'v' })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ a: 'v' }, { k: 'v' })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ a: 'v', k: 'v' }, { k: 'v' })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ k: 'v' }, { a: 'v', k: 'v' })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ a: null }, { a: undefined })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ a: undefined }, { a: null })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ a: null }, { a: null })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ a: undefined }, { a: undefined })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ autoFocus: true }, {})).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ children: '1' }, {})).toBeTruthy(); var lastProps = { style: { width: 1 } }; var nextProps = { style: { width: 2, height: 1 } }; (0, diffProperties_1.default)(lastProps, nextProps); (0, diffProperties_1.default)(nextProps, { style: { width: 3, height: 1 } }); expect(nextProps).toMatchObject({ style: { width: 2, height: 1 } }); expect(lastProps).toMatchObject({ style: { width: 1 } }); var update = function () { nextProps.style = { width: 3, height: 1 }; }; expect(update()).toBeUndefined(); expect(nextProps).toMatchObject({ style: { width: 3, height: 1 } }); var sameFn = function () { return void 0; }; expect(!!(0, diffProperties_1.default)({ a: sameFn }, { a: sameFn })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ a: function () { return void 0; } }, { a: function () { return void 0; } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ style: null }, { style: { width: 5 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({}, { style: { width: 5 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ style: { width: 5 } }, {})).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ style: { width: 5 } }, { style: { width: 5 } })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ style: { width: 5 } }, { style: { width: 6 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ style: { width: 5 } }, { style: { height: 6 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ placeholderStyle: null }, { placeholderStyle: { width: 5 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({}, { placeholderStyle: { width: 5 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ placeholderStyle: { width: 5 } }, {})).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ placeholderStyle: { width: 5 } }, { placeholderStyle: { width: 5 } })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ placeholderStyle: { width: 5 } }, { placeholderStyle: { width: 6 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ placeholderStyle: { width: 5 } }, { placeholderStyle: { height: 6 } })).toBeTruthy(); expect(!!(0, diffProperties_1.default)({ style: { width: 5 }, a: '1', b: null }, { style: { width: 5 }, a: '1', b: undefined })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ placeholderStyle: { width: 5 }, a: '1', b: null }, { placeholderStyle: { width: 5 }, a: '1', b: undefined })).toBeFalsy(); expect(!!(0, diffProperties_1.default)({ children: '1' }, { children: 1 })).toBeTruthy(); expect((0, diffProperties_1.default)({ className: 'foo' }, { style: { width: 5 } })).toEqual([ 'className', '', 'style', null, 'style', { width: 5 }, ]); expect((0, diffProperties_1.default)({ className: 'foo' }, { placeholderStyle: { width: 5 } })).toEqual([ 'className', '', 'placeholderStyle', null, 'placeholderStyle', { width: 5 }, ]); expect((0, diffProperties_1.default)({ style: { width: 5 } }, {})).toEqual(['style', { width: '' }]); expect((0, diffProperties_1.default)({ style: { width: 5 } }, { className: 'foo' })).toEqual([ 'className', 'foo', 'style', { width: '' }, ]); expect((0, diffProperties_1.default)({ style: { width: 5 } }, { placeholderStyle: { width: 5 } })).toEqual([ 'placeholderStyle', null, 'style', { width: '' }, 'placeholderStyle', { width: 5 }, ]); expect((0, diffProperties_1.default)({ placeholderStyle: { width: 5 } }, { style: { width: 5 } })).toEqual([ 'style', null, 'placeholderStyle', { width: '' }, 'style', { width: 5 }, ]); }); });