-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
48 lines (42 loc) · 1.35 KB
/
test.js
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
39
40
41
42
43
44
45
46
47
48
const test = require('ava')
let faker, FakerPlugin, script
test.beforeEach(t => {
faker = (require('require-no-cache')('@faker-js/faker')).faker
FakerPlugin = require('require-no-cache')('./index').Plugin
script = {
config: {
plugins: {
faker: {}
},
variables: {}
},
scenarios: []
}
})
test('sets faker locale', t => {
script.config.plugins.faker.locale = 'de'
FakerPlugin(script)
t.is(faker.locale, 'de')
})
test('creates a random fake value', t => {
const context = { vars: { test: '$faker.name.firstName' } }
const plugin = FakerPlugin(script)
plugin.script.config.processor.fakerPluginCreateVariables(context, undefined, () => undefined)
t.true(typeof context.vars.test === 'string')
t.not(context.vars.test, '$faker.name.firstName')
})
test('uses original variable for invalid faker function', t => {
const context = {
vars: {
test: '$faker.invalid'
}
}
const plugin = FakerPlugin(script)
plugin.script.config.processor.fakerPluginCreateVariables(context, undefined, () => undefined)
t.is(context.vars.test, '$faker.invalid')
})
test('attaches fakerPluginCreateVariables function to beforeScenario hook', t => {
script.scenarios = [{ flow: { get: { url: 'http://test.local' } } }]
FakerPlugin(script)
t.deepEqual(script.scenarios[0].beforeScenario, ['fakerPluginCreateVariables'])
})