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.

Hi, I am curious the status of this emulator feature :slight_smile: I dont see anything about it in the docs yet.

Hey @a2b027479732f76e99ff so there still ongoing work but it’s mostly focused on the new version that will be based on the OSDK. This solution will likely be released publicly in the first half of this year although this has yet to confirmed as there is still some ongoing debate about what testing infrastructure for OSDK backed functions will look like.

In the meantime, if getting access to the current OSS emulator is important for your existing functions codebase, I can reach out through email or you can reach out to your palantir representative.