0

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')
Pierre
  • 51
  • 8
  • What's the actual expression and the input, including the input's class? Which Mule and Munit versions? – aled Oct 26 '21 at 02:10
  • Thank you for checking this. 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')` I have edited the post with these too. Thanks! – Pierre Oct 26 '21 at 02:26

1 Answers1

1

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.

aled
  • 21,330
  • 3
  • 27
  • 34
  • Thank you for this update. I haven't checked this but solved the issue by running the MUnit tests on the latest patched runtime (4.3.0-20210915). It seems this issue was fixed in a previous patch but the MUnit tests were running on the first released 4.3.0 runtime with no patch, hence failing. – Pierre Oct 26 '21 at 23:24