This module contains all functions required to create a Data Weave test

Example

Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
%dw 2.0
import * from dw::test::Tests
---
 "Matcher api" describedBy [
     "It should support nested matching" in  do {
         var payload = {}
         ---
         payload must [
             beObject(),
             $.foo must [
                 beNull()
             ]
         ]
     },
     "It should support simple matching" in do {
         var payload = {}
         ---
         payload must beObject()
     },

     "It should support multiple root cases" in do {
         var payload = {}
         var flowVar = {a: 123}
         ---
         [
             payload must beObject(),
             flowVar must [
                 beObject(),
                 $.a must equalTo(123)
             ]
         ]
     },
     "It should support using custom assertions" in  do {
         var payload = []
         ---
         payload must sizeOf($) > 2
     }
 ]

Functions

describedBy

describedBy(suite: String, testsToRun: Array<() → TestResult>): TestResult

Defines a new test suite with the list of test cases.

Example
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
%dw 2.0
import * from dw::test::Tests
 ---

 "Matcher api" describedBy [
     "It should support nested matching" in  do {
         var payload = {}
         ---
         payload must [
             beObject(),
             $.foo must [
                 beNull()
             ]
         ]
     },
]

in

in(testName: String, testCases: () → MatcherResult): TestResult

Defines a new test case inside a test suite with a single assertion.

Example
Source
1
2
3
"It should support nested matching" in  do {
   "foo" must beString()
}

in(testName: String, callback: Array<() → MatcherResult>): TestResult

Defines a new test case with multiple assertions

Example
Source
1
2
3
4
5
6
7
8
9
10
11
12
 "It should support multiple root cases" in do {
     var payload = {}
     var flowVar = {a: 123}
     ---
    [
        payload must beObject(),
        flowVar must [
             beObject(),
             $.a must equalTo(123)
          ]
      ]
 }

in(testName: String, callback: Array<() → MatcherResult>, skipAll: Boolean): TestResult

Variables

ERROR_STATUS

FAIL_STATUS

OK_STATUS

SKIP_STATUS

Types

TEST_STATUS

Data Type that describes the result of a Test Execution

Definition
1
"ERROR" | "OK" | "FAIL" | "SKIP"

TestResult

Definition
1
{ name: String, time: Number, status: TEST_STATUS, tests?: Array<TestResult>, errorMessage?: String }