Skip to content

Instantly share code, notes, and snippets.

@Qquanwei
Last active March 14, 2019 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Qquanwei/7f78aea738cbb83f674513b027ffc5c6 to your computer and use it in GitHub Desktop.
Save Qquanwei/7f78aea738cbb83f674513b027ffc5c6 to your computer and use it in GitHub Desktop.
import { of, itShouldPath, itShouldProp, equals, allPass, large, less, always } from 'OverAssert';
const data = {
user: {
name: 'Alice',
id: 200
},
expireTime: 200,
expireDay: 10,
}
of(data)
.map(itShouldPath(
['user', 'name'],
equals('Alice'),
always('user.name should be Alice')
))
.map(itShouldPath(
['user', 'id'],
large(0),
always('user.id should large than 0')
))
.map(itShouldProp(
'expireTime',
less(150),
always('expireTime should less than 150')
))
.map(itShouldProp(
'expireDay',
allPass(less(20), large(0)),
always('expireDay should in range (0, 20)')
))
.validate((success, reason) => {
// success = false, reason = "expireTime should less than 150"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment