|
1 |
| -/* eslint-disable */ |
2 |
| -const { assert } = require('chai'); |
3 |
| - |
4 |
| -const fixtures = require('../../fixtures'); |
| 1 | +/* eslint-disable no-new */ |
| 2 | +const { expect } = require('chai'); |
5 | 3 | const { TextDiff } = require('../../../lib/validators/text-diff');
|
6 |
| -const { |
7 |
| - ValidationErrors |
8 |
| -} = require('../../../lib/validators/validation-errors'); |
9 | 4 |
|
10 | 5 | describe('TextDiff', () => {
|
11 |
| - validator = null; |
12 |
| - |
13 |
| - describe('when i create new instance of validator with incorrect "data" (first argument)', () => { |
14 |
| - validator = null; |
15 |
| - |
16 |
| - it('should throw exception', () => { |
| 6 | + describe('when expected non-string data', () => { |
| 7 | + it('should throw an exception', () => { |
17 | 8 | const fn = () => {
|
18 |
| - validator = new TextDiff(null, ''); |
| 9 | + new TextDiff(null, ''); |
19 | 10 | };
|
20 |
| - assert.throws(fn); |
| 11 | + expect(fn).to.throw(); |
21 | 12 | });
|
22 | 13 | });
|
23 | 14 |
|
24 |
| - describe('when i create new instance of validator with incorrect "expected" (second argument)', () => { |
25 |
| - validator = null; |
26 |
| - |
27 |
| - it('should throw exception', () => { |
28 |
| - fn = () => { |
29 |
| - validator = new TextDiff('', null); |
| 15 | + describe('when given non-string actual data', () => { |
| 16 | + it('should throw an exception', () => { |
| 17 | + const fn = () => { |
| 18 | + new TextDiff('', null); |
30 | 19 | };
|
31 |
| - assert.throws(fn); |
| 20 | + expect(fn).to.throw(); |
32 | 21 | });
|
33 | 22 | });
|
34 | 23 |
|
35 |
| - describe('when i create new instance of validator with "Iñtërnâtiônàlizætiøn☃" string as "data"', () => { |
36 |
| - validator = null; |
| 24 | + describe('when expected internationalized string', () => { |
| 25 | + const expected = 'Iñtërnâtiônàlizætiøn☃'; |
37 | 26 |
|
38 |
| - it('should not throw exception', () => { |
39 |
| - const fn = () => { |
40 |
| - validator = new TextDiff('Iñtërnâtiônàlizætiøn☃', ''); |
41 |
| - }; |
42 |
| - assert.doesNotThrow(fn); |
| 27 | + it('should resolve on matching actual string', () => { |
| 28 | + const validator = new TextDiff(expected, expected); |
| 29 | + expect(validator.validate()).to.be.true; |
43 | 30 | });
|
44 | 31 |
|
45 |
| - describe('when I run validate', () => { |
46 |
| - it('should not throw exception', () => { |
47 |
| - const fn = () => validator.validate(); |
48 |
| - assert.doesNotThrow(fn); |
49 |
| - }); |
| 32 | + it('should reject on non-matching actual string', () => { |
| 33 | + const validator = new TextDiff(expected, 'Nâtiônàl'); |
| 34 | + expect(validator.validate()).to.be.false; |
50 | 35 | });
|
51 | 36 | });
|
52 | 37 |
|
53 |
| - describe('when i create new instance of validator with surrogate pair in data', () => { |
54 |
| - validator = null; |
| 38 | + describe('when expected a string with surrogate pair', () => { |
| 39 | + const expected = 'text1\uD800'; |
55 | 40 |
|
56 |
| - it('should not throw exception', () => { |
57 |
| - const fn = () => { |
58 |
| - validator = new TextDiff('text1\uD800', '\uD800text1'); |
59 |
| - }; |
60 |
| - assert.doesNotThrow(fn); |
| 41 | + it('should resolve on matching string', () => { |
| 42 | + const validator = new TextDiff(expected, 'text1\uD800'); |
| 43 | + expect(validator.validate()).to.be.true; |
61 | 44 | });
|
62 | 45 |
|
63 |
| - describe('when I run validate', () => { |
64 |
| - it('should not throw exception', () => { |
65 |
| - const fn = () => validator.validate(); |
66 |
| - assert.doesNotThrow(fn); |
67 |
| - }); |
| 46 | + it('should reject on non-matching string', () => { |
| 47 | + // This is not considered as non-matching strings |
| 48 | + // due to surrogate pairs in it. Rewrite the test. |
| 49 | + const validator = new TextDiff(expected, 'barry'); |
| 50 | + expect(validator.validate()).to.be.false; |
68 | 51 | });
|
69 | 52 | });
|
70 | 53 |
|
71 |
| - describe('when i create new instance of validator with correct data', () => { |
72 |
| - validator = null; |
| 54 | + describe('when expected textual data', () => { |
| 55 | + const expected = 'john'; |
73 | 56 |
|
74 |
| - it('should not throw exception', () => { |
75 |
| - const fn = () => { |
76 |
| - validator = new TextDiff('text1', 'text1'); |
77 |
| - }; |
78 |
| - assert.doesNotThrow(fn); |
| 57 | + it('should resolve when given matching actual data', () => { |
| 58 | + const validator = new TextDiff(expected, 'john'); |
| 59 | + expect(validator.validate()).to.be.true; |
79 | 60 | });
|
80 | 61 |
|
81 |
| - describe('when data are same and I run validate', () => { |
82 |
| - validationResult = null; |
83 |
| - |
84 |
| - before(() => { |
85 |
| - validator = new TextDiff('text1', 'text1'); |
86 |
| - validationResult = validator.validate(); |
87 |
| - }); |
88 |
| - |
89 |
| - it('should set output property', () => { |
90 |
| - assert.isDefined(validator.valid); |
91 |
| - |
92 |
| - it('output should be marked as valid', () => { |
93 |
| - assert.isTrue(validator.vaild); |
94 |
| - }); |
95 |
| - }); |
| 62 | + it('should reject when given non-matching actual data', () => { |
| 63 | + const validator = new TextDiff(expected, 'barry'); |
| 64 | + expect(validator.validate()).to.be.false; |
96 | 65 | });
|
| 66 | + }); |
97 | 67 |
|
98 |
| - describe('when data differs and I run validate', () => { |
99 |
| - validationResult = null; |
100 |
| - |
101 |
| - before(() => { |
102 |
| - validator = new TextDiff('text1', 'text2'); |
103 |
| - validationResult = validator.validate(); |
104 |
| - }); |
| 68 | + describe('when evaluating output to results', () => { |
| 69 | + describe('when expected and actual data match', () => { |
| 70 | + const validator = new TextDiff('john', 'john'); |
| 71 | + validator.validate(); |
| 72 | + const result = validator.evaluateOutputToResults(); |
105 | 73 |
|
106 |
| - it('output property should not be marked as valid', () => { |
107 |
| - assert.isNotTrue(validator.valid); |
| 74 | + it('should return an empty array', () => { |
| 75 | + expect(result).to.be.instanceOf(Array); |
| 76 | + expect(result).to.have.lengthOf(0); |
108 | 77 | });
|
109 | 78 | });
|
110 |
| - }); |
111 | 79 |
|
112 |
| - describe('.evaluateOutputToResults', () => { |
113 |
| - data = null; |
114 |
| - results = null; |
115 |
| - |
116 |
| - describe('empty validation result', () => { |
117 |
| - before(() => { |
118 |
| - validator = new TextDiff('', ''); |
119 |
| - validator.validate(); |
120 |
| - results = validator.evaluateOutputToResults(); |
121 |
| - }); |
| 80 | + describe('when expected and actual data do not match', () => { |
| 81 | + const validator = new TextDiff('john', 'barry'); |
| 82 | + validator.validate(); |
| 83 | + const result = validator.evaluateOutputToResults(); |
122 | 84 |
|
123 | 85 | it('should return an array', () => {
|
124 |
| - assert.isArray(results); |
| 86 | + expect(result).to.be.instanceOf(Array); |
125 | 87 | });
|
126 | 88 |
|
127 |
| - it('should has no results', () => { |
128 |
| - assert.equal(results.length, 0); |
| 89 | + it('should contain exactly one error', () => { |
| 90 | + expect(result).to.have.lengthOf(1); |
129 | 91 | });
|
130 |
| - }); |
131 | 92 |
|
132 |
| - describe('non empty validation result', () => { |
133 |
| - before(() => { |
134 |
| - validator = new TextDiff('abc', 'cde'); |
135 |
| - validator.validate(); |
136 |
| - results = validator.evaluateOutputToResults(); |
| 93 | + it('error should include the "message"', () => { |
| 94 | + expect(result[0]).to.have.property( |
| 95 | + 'message', |
| 96 | + 'Actual and expected data do not match.' |
| 97 | + ); |
137 | 98 | });
|
138 | 99 |
|
139 |
| - it('should return an array', () => { |
140 |
| - assert.isArray(results); |
141 |
| - }); |
142 |
| - |
143 |
| - it('should contain one error', () => { |
144 |
| - assert.lengthOf(results, 1); |
| 100 | + it('error should contain compared values', () => { |
| 101 | + expect(result[0]).to.have.deep.property('values', { |
| 102 | + expected: 'john', |
| 103 | + actual: 'barry' |
| 104 | + }); |
145 | 105 | });
|
146 | 106 | });
|
147 | 107 | });
|
|
0 commit comments