'How to test a PersistentMap item is correctly saved to storage?

I have a function that takes a number of values, creates a new model, and then saves this in storage via a PersistentMap.

I would like to test that the item is successfully saved in storage. This is how I'm going about it:

    it("saves a new item to storage", () => {
      VMContext.setCurrent_account_id("test_account_id");

      contract.createMyPersistantMapItem(
        "value 1",
        "value 2",
        "value 3"
      );
   
      expect(storage.hasKey("myPersistantMap::test_account_id")).toBeTruthy();
    });

However the test fails with the following:

  [Actual]: false
[Expected]: Truthy
   [Stack]: RuntimeError: unreachable
            at node_modules/@as-pect/assembly/assembly/internal/assert/assert (wasm-function[53]:0xd71)
            at start:src/simple/__tests__/index.unit.spec~anonymous|0~anonymous|0~anonymous|0 (wasm-function[130]:0x2a84)
            at node_modules/@as-pect/assembly/assembly/internal/call/__call (wasm-function[134]:0x2aac)

Am I going about this the wrong way?

Also I would like to test the values in the item are correct. In the todos example the created todo is returned from the function that creates it, and then this returned value is tested. Is this the best way of doing things to make testing easier?

EDIT

This is the createMyPersistantMapItem function - edited a bit to make things clearer:

export function createMyPersistantMapItem(
    blah1: string,
    blah2: string,
    blah3: string,
  ): void {
    const accountId = context.sender;
  
    assert(
      !storage.hasKey("myPersistantMap::" + accountId),
      "Item already exists"
    );
  
    const newPersistantMapItem = new PersistantMapItem(
      blah1,
      blah2,
      blah3
    );
  
    myPersistantMap.set(accountId, newPersistantMapItem);
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source