Pierre
Pierre

Reputation: 61

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')

Upvotes: 0

Views: 579

Answers (1)

aled
aled

Reputation: 25699

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.

Upvotes: 1

Related Questions