dataweavemulesoftmunit

Mule Dataweave Assertion Function haveKey is not validating keys with null values



Does anyone know if the DW Assertions Function haveKey is expected to validate a key pair with the key value being null? It seems MUnit fails the assertion if the value is null as shown below:
Expected: to contain key carelineId
Actual: {
carelineId: null
}
at org.mule.munit.assertion.internal.AssertModule.assertMatcherResult(AssertModule.java:77

Pretty clear that the key is there, but its value is null. Thanks!

Edit:

The input is a Transform Message set variable:

%dw 2.0 output application/java  
import * from dw::test::Asserts   
--- 
{
   carelineId: null 
} 

and the expression is:

import * from dw::test::Asserts  
---  
vars.theInput must haveKey('carelineId')

Solution

  • I think the issue is that haveKey() uses as a parameter a matcher, not a string. Example:

    #[MunitTools::hasKey(MunitTools::equalTo('myKey'))
    

    See the docs https://docs.mulesoft.com/munit/2.3/munit-matchers

    Note that these are Munit assertions and matchers.