@@ -74,7 +74,7 @@ Hopefully our `Model` class is self explanatory, but as an example,
74
74
here we construct a person object.
75
75
76
76
``` javascript
77
- var arthur = new Model (' person' );
77
+ const arthur = new Model (' person' );
78
78
arthur .set (' name' , ' Arthur Dent' );
79
79
arthur .set (' occupation' , ' traveller' );
80
80
console .log (arthur .get (' name' )); // Arthur Dent
@@ -97,7 +97,7 @@ implementation throughout.
97
97
For this example, we want the following test case to pass:
98
98
99
99
``` javascript
100
- var arthur = new Model (' person' );
100
+ const arthur = new Model (' person' );
101
101
expect (arthur).to .be .a .model ;
102
102
```
103
103
@@ -141,7 +141,7 @@ expect(arthur).to.be.a.model('person');
141
141
142
142
// language chain method
143
143
Assertion .addMethod (' model' , function (type ) {
144
- var obj = this ._obj ;
144
+ const obj = this ._obj ;
145
145
146
146
// first, our instanceof check, shortcut
147
147
new Assertion (this ._obj ).to .be .instanceof (Model);
@@ -176,8 +176,8 @@ To understand when to best use chainable methods we will examine a chainable met
176
176
core.
177
177
178
178
` ` ` javascript
179
- var arr = [ 1 , 2 , 3 ]
180
- , obj = { a: 1 , b: 2 };
179
+ const arr = [ 1 , 2 , 3 ];
180
+ const obj = { a: 1 , b: 2 };
181
181
182
182
expect (arr).to .contain (2 );
183
183
expect (obj).to .contain .key (' a' );
@@ -241,7 +241,7 @@ function assertModelAge (n) {
241
241
new Assertion (this ._obj ).to .be .instanceof (Model);
242
242
243
243
// make sure we have an age and its a number
244
- var age = this ._obj .get (' age' );
244
+ const age = this ._obj .get (' age' );
245
245
new Assertion (age).to .be .a (' number' );
246
246
247
247
// do our comparison
@@ -301,7 +301,7 @@ Let's start out with the basic overwrite utility and a basic assertion.
301
301
` ` ` javascript
302
302
chai .overwriteProperty (' ok' , function (_super ) {
303
303
return function checkModel () {
304
- var obj = this ._obj ;
304
+ const obj = this ._obj ;
305
305
if (obj && obj instanceof Model) {
306
306
new Assertion (obj).to .have .deep .property (' _attrs.id' ).a (' number' );
307
307
} else {
@@ -324,7 +324,7 @@ will serve as the actual assertion.
324
324
With this in place, we can write positive assertions.
325
325
326
326
` ` ` javascript
327
- var arthur = new Model (' person' );
327
+ const arthur = new Model (' person' );
328
328
arthur .set (' id' , 42 );
329
329
expect (arthur).to .be .ok ;
330
330
expect (true ).to .be .ok ;
@@ -336,7 +336,7 @@ revert to the original behavior. We will, however, run into a bit of
336
336
trouble if we try to negate an ` ok` assertion on a model.
337
337
338
338
` ` ` javascript
339
- var arthur = new Model (' person' );
339
+ const arthur = new Model (' person' );
340
340
arthur .set (' id' , ' dont panic' );
341
341
expect (arthur).to .not .be .ok ;
342
342
` ` `
@@ -355,10 +355,10 @@ property overwrite would look like this.
355
355
` ` ` javascript
356
356
chai .overwriteProperty (' ok' , function (_super ) {
357
357
return function checkModel () {
358
- var obj = this ._obj ;
358
+ const obj = this ._obj ;
359
359
if (obj && obj instanceof Model) {
360
360
new Assertion (obj).to .have .deep .property (' _attrs.id' ); // we always want this
361
- var assertId = new Assertion (obj ._attrs .id );
361
+ const assertId = new Assertion (obj ._attrs .id );
362
362
utils .transferFlags (this , assertId, false ); // false means don't transfer `object` flag
363
363
assertId .is .a (' number' );
364
364
} else {
@@ -380,7 +380,7 @@ for the wrong type of id attribute, we would get an error message that states
380
380
test suite, so we will provide it with a bit more information.
381
381
382
382
` ` ` javascript
383
- var assertId = new Assertion (obj ._attrs .id , ' model assert ok id type' );
383
+ const assertId = new Assertion (obj ._attrs .id , ' model assert ok id type' );
384
384
` ` `
385
385
386
386
This will change our error message to be a more informative ` model assert ok id type:
@@ -393,7 +393,7 @@ For this example we will be returning to our example of asserting Arthur's
393
393
age to be above a minimum threshold.
394
394
395
395
` ` ` javascript
396
- var arthur = new Model (' person' );
396
+ const arthur = new Model (' person' );
397
397
arthur .set (' age' , 27 );
398
398
expect (arthur).to .have .age .above (17 );
399
399
` ` `
@@ -405,7 +405,7 @@ so all we have to do is check if that exists.
405
405
Assertion .overwriteMethod (' above' , function (_super ) {
406
406
return function assertAge (n ) {
407
407
if (utils .flag (this , ' model.age' )) {
408
- var obj = this ._obj ;
408
+ const obj = this ._obj ;
409
409
410
410
// first we assert we are actually working with a model
411
411
new Assertion (obj).instanceof (Model);
@@ -414,7 +414,7 @@ Assertion.overwriteMethod('above', function (_super) {
414
414
new Assertion (obj).to .have .deep .property (' _attrs.age' ).a (' number' );
415
415
416
416
// now we compare
417
- var age = obj .get (' age' );
417
+ const age = obj .get (' age' );
418
418
this .assert (
419
419
age > n
420
420
, " expected #{this} to have an age above #{exp} but got #{act}"
0 commit comments