Typescript Unit Testing: Advice & Guidance

Is there any good example documentation on how to debug setting up unit tests in Typescript repos? I see the implementation documentation here but that falls a bit short when trying to debug .

For example, I get :

    Expected function to create an object ObjectType(objectId: "Testing Scenario_1234")

      56 |             true,
      57 |             true,
    > 58 |         ))).createsObject({
         |             ^
      59 |             objectType: ObjectType,
      60 |             properties: {
      61 |                 objectId: "Testing Scenario_1234",

Which is super helpful to know that it failed but there doesn’t appear to be any way to understand what has been created. Additionally it doesn’t appear that there is an easy way to confirm that your object stub is working correctly, as I have a number of failed upstream object searches.

Hi @callum_mccann , have you tried using the debugger functionality in tests documented here? If you have a complicated test, it may help to step through to get a better sense of what each line is doing.

Debugging was definitely helpful here! I’ll be honest, I’d always wondered what the breakpoint functionality did because it never worked when executing Live Functions.

For anyone who comes across this thread, the answer to my question is that inputs need to be exactly the same as what is being stubbed.

So in the below example I had to hard-code the specific test Ids that will be the input to the stub. When I added another test id into the function with a different generated mock, it failed because suddenly the tested object search and the stubbed mock weren’t 1:1.

        const testIds = ['1234'];

        whenObjectSet(
            Objects.search()
                .testObject()
                .filter(o => o.testId.exactMatch(...testIds))
                .all()
            ).thenReturn(stubMocks.testMock);

Bit annoying that it has to be exactly perfect but understand we don’t want there to be any leaky abstractions in a unit test so it makes sense.

The breakpoint functionality is currently only supported for Jest tests. Debugging live Function execution is in the works, however.