Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit d9e4a9e

Browse files
author
Bassem Dghaidi
committed
Add closure testing scenario
1 parent 31ed5f3 commit d9e4a9e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,44 @@ console.dir(result, {depth: null});
220220
}
221221
```
222222

223+
### 6. Match with closures (Success)
224+
225+
You can use closures for testing
226+
227+
```javascript
228+
const match = require('@menadevs/objectron');
229+
230+
const payload = {
231+
'type': 'message',
232+
'text': 'text',
233+
'int': 1,
234+
'bool': true,
235+
'float': 1.1,
236+
'items': [1, 1, 1, 1],
237+
}
238+
239+
const tester = {
240+
'type': (val) => val === 'message',
241+
'text': (val) => val.length == 4,
242+
'int': (val) => val + 1 == 2,
243+
'bool': (val) => !!!!!!!!val,
244+
'float': (val) => val - 1.1 == 0,
245+
'items': (val) => val.length == 4,
246+
}
247+
248+
const result = match(payload, tester);
249+
250+
console.dir(result, {depth: null});
251+
252+
# Output
253+
> {
254+
match: true,
255+
total: 0,
256+
matches: { type: {}, text: {}, int: {}, bool: {}, float: {}, items: {} },
257+
groups: {}
258+
}
259+
```
260+
223261
## Meta
224262

225263
- [@Link-](https://github.com/Link-)

0 commit comments

Comments
 (0)