apphouse
Version:
Component library for React that uses observable state management and theme-able components.
58 lines (54 loc) • 1.1 kB
text/typescript
import { merge } from './merge';
describe('merge', () => {
test('should merge two objects', () => {
const obj1 = {
name: 'John'
};
const obj2 = {
age: 20
};
const newObj = merge(obj1, obj2);
expect(newObj).toEqual({
name: 'John',
age: 20
});
});
test('should overwrite properties in the first object', () => {
const obj1 = {
name: 'John',
age: 20
};
const obj2 = {
age: 25
};
const newObj = merge(obj1, obj2);
expect(newObj).toEqual({
name: 'John',
age: 25
});
});
test('should merge recursively', () => {
const styles1 = {
backgroundColor: 'red',
':hover': {
backgroundColor: 'blue'
}
};
const styles2 = {
backgroundColor: 'blue',
color: 'green',
':hover': {
color: 'yellow'
}
};
const styles = merge(styles1, styles2);
expect(styles).toEqual({
backgroundColor: 'blue',
color: 'green',
':hover': {
backgroundColor: 'blue',
color: 'yellow'
}
});
});
});