-
Notifications
You must be signed in to change notification settings - Fork 1
/
steps.test.js
99 lines (77 loc) · 3.21 KB
/
steps.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
'use strict'
const path = require('path')
const chai = require('chai')
chai.should()
const expect = chai.expect
const fs = require('fs').promises
const helpers = require('./helpers')
const Steps = require('../steps')
describe('steps', function () {
describe('the constructor Steps(listSteps, context)', function () {
describe('the first parameter "listSteps"', function () {
it('expects an array', function () {
expect(function () {
new Steps([], {})
}).to.not.throw()
})
it('throws a TypeError, if passed data is not a list', function () {
expect(function () {
new Steps('This is not a list', {})
}).to.throw(TypeError)
expect(function () {
new Steps({})
}).to.throw(TypeError)
})
it('throws a ReferenceError, if no data is passed at all', function () {
expect(function () {
new Steps(undefined, {})
}).to.throw(ReferenceError)
})
})
describe('the second parameter "context"', function () {
it('expects an object', function () {
expect(function () {
new Steps([], {})
}).to.not.throw()
})
it('throws a TypeError if passed data is not a json object', function () {
expect(function () {
new Steps([], 'This is not an object')
}).to.throw(TypeError)
expect(function () {
new Steps([], 'a string')
}).to.throw(TypeError)
expect(function () {
new Steps([], [])
}).to.throw(TypeError)
})
it('throws a ReferenceError if no data is passed at all', function () {
expect(function () {
new Steps([])
}).to.throw(ReferenceError)
})
})
})
describe('Steps.prototype.render()', function () {
context('this.jsonData is valid', function () {
it('can render an empty Steps container', async function () {
const steps = new Steps([], {})
const htmlRendered = steps.render()
const htmlExpected = await fs.readFile(path.join(__dirname, 'mock-data', 'steps', 'mock-steps-empty.html'), 'utf8')
helpers.stripWhitespaces(htmlRendered).should.equal(helpers.stripWhitespaces(htmlExpected))
})
it('can render multiple empty Steps into the container', async function () {
const steps = new Steps([
{},
{},
{}
], {})
const htmlRendered = steps.render()
const htmlExpected = await fs.readFile(path.join(__dirname, 'mock-data', 'steps', 'mock-steps-multiple-empty.html'), 'utf8')
helpers.stripWhitespaces(htmlRendered).should.equal(helpers.stripWhitespaces(htmlExpected))
})
// context('this.jsonData is invalid', function() {
// })
})
})
})