Skip to content

Instantly share code, notes, and snippets.

@marcelmokos
Created March 10, 2023 00:49
Show Gist options
  • Save marcelmokos/6f7a48f2ec2d74cead881d2b16da68a8 to your computer and use it in GitHub Desktop.
Save marcelmokos/6f7a48f2ec2d74cead881d2b16da68a8 to your computer and use it in GitHub Desktop.
import { getChangesOnList } from './getChangesOnList';
describe('getChangesOnList', () => {
it('should return the correct changes', () => {
const prev = [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
];
const curr = [
{ id: 1, name: 'foo' },
{ id: 2, name: 'baz' },
{ id: 3, name: 'qux' },
];
const changes = getChangesOnList(prev, curr);
expect(changes).toEqual({
add: [{ id: 3, name: 'qux' }],
update: [{ id: 2, name: 'baz' }],
remove: [],
});
});
it('should return the correct changes when the list is empty', () => {
const prev = [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
];
const curr = [];
const changes = getChangesOnList(prev, curr);
expect(changes).toEqual({
add: [],
update: [],
remove: [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
],
});
});
it('should return the correct changes when the list is empty', () => {
const prev = [];
const curr = [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
];
const changes = getChangesOnList(prev, curr);
expect(changes).toEqual({
add: [
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
],
update: [],
remove: [],
});
});
it('should return the correct changes when the list is empty', () => {
const prev = [];
const curr = [];
const changes = getChangesOnList(prev, curr);
expect(changes).toEqual({
add: [],
update: [],
remove: [],
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment