Skip to content

Commit a9a7ee1

Browse files
test: split example and property tests
1 parent 1f8ba5e commit a9a7ee1

File tree

4 files changed

+74
-68
lines changed

4 files changed

+74
-68
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"build-mangle": "browserify . -s unistUtilIs -o unist-util-is.min.js -p tinyify",
5656
"build": "npm run build-bundle && npm run build-mangle",
5757
"test-api": "node test",
58-
"test-coverage": "nyc --reporter lcov tape test.js",
58+
"test-coverage": "nyc --reporter lcov tape test",
5959
"test-types": "dtslint .",
6060
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
6161
},

test.js renamed to test/example.js

Lines changed: 2 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
'use strict'
22

33
var test = require('tape')
4-
var fc = require('fast-check')
5-
var _ = require('lodash')
6-
var is = require('.')
4+
var is = require('..')
75

8-
test('unist-util-is', function (t) {
6+
test('unist-util-is example', function (t) {
97
var node = {type: 'strong'}
108
var parent = {type: 'paragraph', children: []}
119

@@ -133,66 +131,3 @@ test('unist-util-is', function (t) {
133131

134132
t.end()
135133
})
136-
137-
test('unist-util-is properties', function (t) {
138-
t.plan(4)
139-
t.doesNotThrow(function () {
140-
fc.assert(
141-
fc.property(
142-
fc.record({type: fc.string({minLength: 1})}),
143-
function (node) {
144-
return is(node)
145-
}
146-
)
147-
)
148-
}, 'should check if given node (#1)')
149-
150-
t.doesNotThrow(function () {
151-
fc.assert(
152-
fc.property(
153-
fc.dictionary(fc.string(), fc.string()).filter(function (node) {
154-
return typeof node.type === 'undefined'
155-
}),
156-
function (node) {
157-
return !is(node)
158-
}
159-
)
160-
)
161-
}, 'should check if given node (#2)')
162-
163-
t.doesNotThrow(function () {
164-
fc.assert(
165-
fc.property(
166-
fc.record({type: fc.string({minLength: 1})}),
167-
function (node) {
168-
return is(node, node.type)
169-
}
170-
)
171-
)
172-
}, 'should match types')
173-
174-
t.doesNotThrow(function () {
175-
fc.assert(
176-
fc.property(
177-
fc
178-
// generate an object with primitive values
179-
.dictionary(
180-
fc.string(),
181-
fc.oneof(fc.string(), fc.integer(), fc.bigInt(), fc.boolean())
182-
)
183-
// object must have some keys
184-
.filter(function (node) { return _.keys(node).length > 1})
185-
// return node and a list with a random subset of it's keys
186-
.chain(function (node) {
187-
return fc.tuple(fc.constant(node), fc.subarray(_.keys(node), {minLength: 1}))
188-
}),
189-
fc.string({minLength: 1}),
190-
function (nodeAndKeys, type) {
191-
var node = nodeAndKeys[0]
192-
var keys = nodeAndKeys[1]
193-
return is(_.assign(node, {type: type}), _.pick(_.cloneDeep(node), keys))
194-
}
195-
)
196-
)
197-
}, 'should match partially')
198-
})

test/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require("./example")
2+
require("./property")

test/property.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict'
2+
3+
var test = require('tape')
4+
var fc = require('fast-check')
5+
var _ = require('lodash')
6+
var is = require('..')
7+
8+
test('unist-util-is properties', function (t) {
9+
t.plan(4)
10+
t.doesNotThrow(function () {
11+
fc.assert(
12+
fc.property(
13+
fc.record({type: fc.string({minLength: 1})}),
14+
function (node) {
15+
return is(node)
16+
}
17+
)
18+
)
19+
}, 'should check if given node (#1)')
20+
21+
t.doesNotThrow(function () {
22+
fc.assert(
23+
fc.property(
24+
fc.dictionary(fc.string(), fc.string()).filter(function (node) {
25+
return typeof node.type === 'undefined'
26+
}),
27+
function (node) {
28+
return !is(node)
29+
}
30+
)
31+
)
32+
}, 'should check if given node (#2)')
33+
34+
t.doesNotThrow(function () {
35+
fc.assert(
36+
fc.property(
37+
fc.record({type: fc.string({minLength: 1})}),
38+
function (node) {
39+
return is(node, node.type)
40+
}
41+
)
42+
)
43+
}, 'should match types')
44+
45+
t.doesNotThrow(function () {
46+
fc.assert(
47+
fc.property(
48+
fc
49+
// generate an object with primitive values
50+
.dictionary(
51+
fc.string(),
52+
fc.oneof(fc.string(), fc.integer(), fc.bigInt(), fc.boolean())
53+
)
54+
// object must have some keys
55+
.filter(function (node) { return _.keys(node).length > 1})
56+
// return node and a list with a random subset of it's keys
57+
.chain(function (node) {
58+
return fc.tuple(fc.constant(node), fc.subarray(_.keys(node), {minLength: 1}))
59+
}),
60+
fc.string({minLength: 1}),
61+
function (nodeAndKeys, type) {
62+
var node = nodeAndKeys[0]
63+
var keys = nodeAndKeys[1]
64+
return is(_.assign(node, {type: type}), _.pick(_.cloneDeep(node), keys))
65+
}
66+
)
67+
)
68+
}, 'should match partially')
69+
})

0 commit comments

Comments
 (0)