var assert = require('chai').assert; var React = require('react'); var shallowElementEquals = require('../'); const Foo = () => {}; const Bar = () => {}; describe('shallowElementEquals(a, b)', () => { describe('succeeds on', () => { it('single child and no props', () => { const a = ( ); const b = ( ); assert(shallowElementEquals(a.props, b.props)); }); it('multiple child and no props', () => { const a = ( ); const b = ( ); assert(shallowElementEquals(a.props, b.props)); }); it('multiple children from array', () => { const a = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); const b = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); assert(shallowElementEquals(a.props, b.props)); }); it('multiple children from array and arguments', () => { const a = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); const b = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); assert(shallowElementEquals(a.props, b.props)); }); it('nested children', () => { const a = ( ); const b = ( ); assert(shallowElementEquals(a.props, b.props)); }); it('style props', () => { const a = ( ); const b = ( ); assert(shallowElementEquals(a.props, b.props)); }); }); describe('fails on', () => { it('single child with different props', () => { const a = ( ); const b = ( ); assert(!shallowElementEquals(a.props, b.props)); }); it('single nested child with different props', () => { const a = ( ); const b = ( ); assert(!shallowElementEquals(a.props, b.props)); }); it('array of children with different lengths', () => { const a = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); const b = ( {Array.from({ length: 9 }).map((_, i) => ( ))} ); assert(!shallowElementEquals(a.props, b.props)); }); it('array of children with elements switched', () => { const a = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); const children = Array.from({ length: 9 }).map((_, i) => ( )); children.splice(5, 0, ); const b = ( {children} ); assert(!shallowElementEquals(a.props, b.props)); }); it('array of children with elements switched', () => { const a = ( {Array.from({ length: 10 }).map((_, i) => ( ))} ); const children = Array.from({ length: 10 }).map((_, i) => ( )); children.splice(5, 1, ); const b = ( {children} ); assert(!shallowElementEquals(a.props, b.props)); }); it('single element with new object prop', () => { const a = ( ); const b = ( ); assert(!shallowElementEquals(a.props, b.props)); }); it('style props', () => { const a = ( ); const b = ( ); assert(!shallowElementEquals(a.props, b.props)); }); }); });