Created
March 10, 2023 00:49
-
-
Save marcelmokos/6f7a48f2ec2d74cead881d2b16da68a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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