Skip to content

Commit

Permalink
add test for items order on update events
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusheine committed May 7, 2022
1 parent 7a588a0 commit 2d0f791
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/useFind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,36 @@ describe('Find composition', () => {
expect(findComposition && findComposition.data.value).toContainEqual(changedTestModel);
});

it('should keep order of items when handling "update" events', async () => {
expect.assertions(3);

// given
const emitter = eventHelper();
const feathersMock = {
service: () => ({
find: jest.fn(() => [additionalTestModel2, testModel, additionalTestModel]),
on: emitter.on,
off: jest.fn(),
}),
on: jest.fn(),
off: jest.fn(),
} as unknown as Application;
const useFind = useFindOriginal(feathersMock);
let findComposition = null as UseFind<TestModel> | null;
mountComposition(() => {
findComposition = useFind('testModels');
});
await nextTick();

// when
emitter.emit('updated', changedTestModel);

// then
expect(findComposition).toBeTruthy();
expect(findComposition && findComposition.data.value).toHaveLength(3);
expect(findComposition && findComposition.data.value[1]).toStrictEqual(changedTestModel);
});

it('should listen to "patch" & "update" events when query is matching', async () => {
expect.assertions(2);

Expand Down

0 comments on commit 2d0f791

Please sign in to comment.