diff --git a/test/useFind.test.ts b/test/useFind.test.ts index 00bd144..d920e02 100644 --- a/test/useFind.test.ts +++ b/test/useFind.test.ts @@ -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 | 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);