Skip to content

Commit

Permalink
Add property based tests using fast-check (#62)
Browse files Browse the repository at this point in the history
This commit is a follow up of the issues opened by @rix0rrr recently:
- #56
- #57
- #59
  • Loading branch information
dubzzz authored and eemeli committed Dec 23, 2018
1 parent cd859c8 commit 8ef5c0d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
35 changes: 35 additions & 0 deletions __tests__/properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import YAML from '../src/index'
import * as fc from 'fast-check'

describe('properties', () => {
test('parse stringified object', () => {
const key = fc.fullUnicodeString()
const values = [
key,
fc.lorem(1000, false), // words
fc.lorem(100, true), // sentences
fc.boolean(),
fc.integer(),
fc.double(),
fc.constantFrom(null, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY)
]
const yamlArbitrary = fc.anything({ key: key, values: values })
const optionsArbitrary = fc.record(
{
keepBlobsInJSON: fc.boolean(),
keepCstNodes: fc.boolean(),
keepNodeTypes: fc.boolean(),
mapAsMap: fc.constant(false),
merge: fc.boolean(),
schema: fc.constantFrom('core', 'yaml-1.1') // ignore 'failsafe', 'json'
},
{ withDeletedKeys: true }
)

fc.assert(
fc.property(yamlArbitrary, optionsArbitrary, (obj, opts) => {
expect(YAML.parse(YAML.stringify(obj, opts), opts)).toStrictEqual(obj)
})
)
})
})
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"babel-jest": "^23.6.0",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-plugin-trace": "^1.1.0",
"fast-check": "^1.8.2",
"jest": "^23.6.0",
"prettier": "^1.15.3"
},
Expand Down

0 comments on commit 8ef5c0d

Please sign in to comment.