---
schema_version: "1"
id: 177ade6e09d34cef11bd0375c9ec67a15861d11ad49e3bf2631f6bde53120983
title: MUnit DataWeave Assertions Library
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/munit/latest/dataweave-assertions-library.md
canonical_url: https://docs.mulesoft.com/munit/latest/dataweave-assertions-library
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 355bda51995601bad8381a2196675ddf0a8ee70bfe44f8c73e6e9df64c83bb3c
description: MuleSoft Documentation Site
release: "3.7"
latest: true
---
---
product: MUnit
version: 3.7
is-latest-version: true
---

# MUnit DataWeave Assertions Library

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

![logo acb active](/mulesoft/current/en-us/_/img/icons/anypoint-code-builder.svg "Anypoint Code Builder")Anypoint Code
Builder

![logo studio active](/mulesoft/current/en-us/_/img/icons/studio.svg "Anypoint Studio")Anypoint Studio

The MUnit DataWeave Assertions Library is a set of DataWeave matcher functions for writing
assertions in MUnit tests. Use it with the Assert Expression processor to validate values such as
strings, numbers, arrays, and objects using DataWeave syntax.

## dw::test::Asserts

This module contains the set of core Matchers to use in your tests

Example

```dataweave
%dw 2.0
import dw::test::Asserts
---
payload must beObject()
```

Validates if a payload is of type Object

## Functions

### anyOf

#### anyOf(Array<Matcher<Any>>): Matcher<Any>

Validates that the value satisfies at least one of the given matchers

```dataweave
%dw 2.0
import dw::test::Asserts
---
"A Text" must anyOf([beObject(), beString()])
```

### beArray

#### beArray(): Matcher

Validates that a given value is of type Array

```dataweave
%dw 2.0
import dw::test::Asserts
---
[1, 4, 7] must beArray()
```

### beBlank

#### beBlank(): Matcher<String | Null>

Validates that the String value is blank

```dataweave
%dw 2.0
import dw::test::Asserts
---
"  " must beBlank()
```

### beBoolean

#### beBoolean(): Matcher

Validates that a given value is of type Boolean

```dataweave
%dw 2.0
import dw::test::Asserts
---
true must beBoolean()
```

### beEmpty

#### beEmpty(): Matcher<String | Object | Array | Null>

Validates that the value (String, Object or Array) is empty

```dataweave
%dw 2.0
import dw::test::Asserts
---
[] must beEmpty()
```

### beGreaterThan

#### beGreaterThan(Comparable, Boolean): Matcher<Comparable>

Validates that the asserted Comparable value is greater than the given one

Can be equal to when using the _inclusive_ argument

```dataweave
%dw 2.0
import dw::test::Asserts
---
3 must beGreaterThan(2)
```

### beLowerThan

#### beLowerThan(Comparable, Boolean): Matcher<Comparable>

Validates that the asserted Comparable value is lower than the given one

Can be equal to when using the _inclusive_ argument

```dataweave
%dw 2.0
import dw::test::Asserts
---
1 must beLowerThan(2)
```

### beNull

#### beNull(): Matcher

Validates that a given value is of type Null

```dataweave
%dw 2.0
import dw::test::Asserts
---
null must beNull()
```

### beNumber

#### beNumber(): Matcher

Validates that a given value is of type Number

```dataweave
%dw 2.0
import dw::test::Asserts
---
123 must beNumber()
```

### beObject

#### beObject(): Matcher

Validates that a given value is of type Object

```dataweave
%dw 2.0
import dw::test::Asserts
---
{ name : "Lionel", lastName: "Messi"} must beObject()
```

### beOneOf

#### beOneOf(Array<Any>): Matcher

Validates that the value is contained in the given Array

```dataweave
%dw 2.0
import dw::test::Asserts
---
1 must beOneOf([1, "A Text", true])
```

### beString

#### beString(): Matcher

Validates that a given value is of type String

```dataweave
%dw 2.0
import dw::test::Asserts
---
"A Text" must beString()
```

### contain

#### contain(String): Matcher<String>

Validates that the asserted String contains the given String

```dataweave
%dw 2.0
import dw::test::Asserts
---
"A Text" must contain("ex")
```

#### contain(Any): Matcher<Array<Any>>

Validates that the asserted Array contains the given value

```dataweave
%dw 2.0
import dw::test::Asserts
---
[1, "A Text", true] must contain(1)
```

### eachItem

#### eachItem(Matcher<Any>): Matcher<Array<Any>>

Validates that each item of the array satisfies the given matcher

```dataweave
%dw 2.0
import dw::test::Asserts
---
[1,2,3] must eachItem(beNumber())
```

### endWith

#### endWith(String): Matcher<String>

Validates that the asserted String ends with the given String

```dataweave
%dw 2.0
import dw::test::Asserts
---
"A Text" must endWith("xt")
```

### equalTo

#### equalTo(Any, { unordered?: Boolean }): Matcher<Any>

Validates that a value is equal to another one

```dataweave
%dw 2.0
import dw::test::Asserts
---
(1 + 2) must equalTo(3)
```

### equalToResource

#### equalToResource(String, String, Object): Matcher<Any>

Validates that the given value is equal to the content of a resource file

The resource file must belong to the classpath

```dataweave
%dw 2.0
import dw::test::Asserts
---
{ name: "Lionel", lastName: "Messi" } must equalToResource("user.json", "application/json")
```

### haveItem

#### haveItem(Matcher<Any>): Matcher<Array<Any>>

Validates that at least one item of the array satisfies the given matcher

```dataweave
%dw 2.0
import dw::test::Asserts
---
[1, true, "a text"] must haveItem(beNumber())
```

### haveKey

#### haveKey(String): Matcher<Object>

Validates that the Object has the given key

```dataweave
%dw 2.0
import dw::test::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveKey("name")
```

### haveSize

#### haveSize(Number): Matcher<Array | String | Object>

Validates that the array has the given size

```dataweave
%dw 2.0
import dw::test::Asserts
---
[1, 4, 7] must haveSize(3)
```

### haveValue

#### haveValue(Any): Matcher<Object>

Validates that the Object has the given value

```dataweave
%dw 2.0
import dw::test::Asserts
---
{ name: "Lionel", lastName: "Messi" } must haveValue("Messi")
```

### must

#### must(T, Array<(value: T) → Matcher<T> | MatcherResult | Boolean>): MatcherResult

This function allows to assert a value with a list of Matcher of Expressions

Example

```dataweave
%dw 2.0
import dw::test::Asserts
---
payload must [
    beObject(),
    $.foo is Null
]
```

#### must(T, (value: T) → Matcher<T> | Boolean): MatcherResult

This function allows to assert a value with a Matcher of Expressions

Example

```dataweave
%dw 2.0
import dw::test::Asserts
---
payload must beObject()
```

### notBe

#### notBe(Matcher<T>): Matcher<T>

Validates that the value doesn’t satisfy the given matcher

```dataweave
%dw 2.0
import dw::test::Asserts
---
1 must notBe(equalTo(2))
```

### notBeNull

#### notBeNull(): Matcher

Validates that a given value isn’t of type Null

```dataweave
%dw 2.0
import dw::test::Asserts
---
"A Text" must notBeNull()
```

### startWith

#### startWith(String): Matcher<String>

Validates that the asserted String starts with the given String

```dataweave
%dw 2.0
import dw::test::Asserts
---
"A Text" must startWith("A")
```

## Variables

### MATCHED

Constant that represents a successful match

## Types

### Matcher

Data Type that represents a Matcher to perform assertions

Example

```dataweave
%dw 2.0
import dw::test::Asserts

fun beEqualToOne(): Matcher<Any> =
    (actual) -> do {
        {
            matches: actual == 1,
            description: { expected: "To be 1", actual: write(actual) as String }
        }
    }
```

Definition

```dataweave
(value: T) -> MatcherResult
```

### MatcherResult

Data Type that represents the result of an Assertion

Example

```dataweave
{
  "matches": false,
  description : { expected : "Number type", actual: "A Text" }
}
```

Definition

```dataweave
{ matches: Boolean, description: { expected: String, actual: String }, reasons?: Array<String> }
```
