How to create TypeScript Unit Tests for functions have an Object Set input

Hi I have a function which uses ObjectSet as an input. I’m creating unit tests but it doesn’t work. Below is my function and the unit test code.

    @Function()
    public async testFunction (testObjectSet: ObjectSet<fakeObject>): Promise<ObjectSet<fakeObject>> {
        
        const result = await testObjectSet 
        .groupBy(obj => obj.title.exactValues({maxBuckets: 10})) 
        .max(obj => obj.submittedAt); 

        const newResult = fakeObject.filter(note => 
            note.submittedAt.exactMatch(result.buckets.find(group => note.title.exactMatch(group.key))?.value!)   
        );

        return newResult;
    }
whenObjectSet(Objects.search().fakeObject().all()).thenReturn(stubSet);
        var temp = Objects.search().fakeObject()
        var result =  await (await myFunctions.testFunction(temp))
1 Like

I believe Objects.search() doesn’t work in tests and will just return undefined - do you have to take in an object set or could you pass in a list of objects instead? Something like myObject[]

I could pass an array of objects, then won’t be able to use the ObjectSet related functions.

Hey @Jzzz! There is an emulator feature in development that will allow you to mimic a the behavior of queries within a unit test. This emulator will use the data created in your unit test and most queries will just work like you would expect (there will be some functionality that will still require stubbing such as fuzzy searches). This feature should available in beta later this year or early next year.