chai 5.0.0 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -25
- package/lib/chai/assertion.js +1 -1
- package/lib/chai/core/assertions.js +59 -6
- package/lib/chai/interface/assert.js +17 -16
- package/package.json +7 -8
- package/bower.json +0 -26
- package/chai.js +0 -4119
- package/karma.conf.cjs +0 -35
- package/karma.sauce.js +0 -41
- package/sauce.browsers.js +0 -106
package/README.md
CHANGED
|
@@ -71,32 +71,12 @@ You can also use it within the browser; install via npm and use the `chai.js` fi
|
|
|
71
71
|
Import the library in your code, and then pick one of the styles you'd like to use - either `assert`, `expect` or `should`:
|
|
72
72
|
|
|
73
73
|
```js
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var should = chai.should(); // Using Should style
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### Pre-Native Modules Usage (_registers the chai testing style globally_)
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
require('chai/register-assert'); // Using Assert style
|
|
84
|
-
require('chai/register-expect'); // Using Expect style
|
|
85
|
-
require('chai/register-should'); // Using Should style
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Pre-Native Modules Usage (_as local variables_)
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
const { assert } = require('chai'); // Using Assert style
|
|
92
|
-
const { expect } = require('chai'); // Using Expect style
|
|
93
|
-
const { should } = require('chai'); // Using Should style
|
|
94
|
-
should(); // Modifies `Object.prototype`
|
|
95
|
-
|
|
96
|
-
const { expect, use } = require('chai'); // Creates local variables `expect` and `use`; useful for plugin use
|
|
74
|
+
import { assert } from 'chai'; // Using Assert style
|
|
75
|
+
import { expect } from 'chai'; // Using Expect style
|
|
76
|
+
import { should } from 'chai'; // Using Should style
|
|
97
77
|
```
|
|
98
78
|
|
|
99
|
-
###
|
|
79
|
+
### Register the chai testing style globally
|
|
100
80
|
|
|
101
81
|
```js
|
|
102
82
|
import 'chai/register-assert'; // Using Assert style
|
|
@@ -104,13 +84,15 @@ import 'chai/register-expect'; // Using Expect style
|
|
|
104
84
|
import 'chai/register-should'; // Using Should style
|
|
105
85
|
```
|
|
106
86
|
|
|
107
|
-
###
|
|
87
|
+
### Import assertion styles as local variables
|
|
108
88
|
|
|
109
89
|
```js
|
|
110
90
|
import { assert } from 'chai'; // Using Assert style
|
|
111
91
|
import { expect } from 'chai'; // Using Expect style
|
|
112
92
|
import { should } from 'chai'; // Using Should style
|
|
113
93
|
should(); // Modifies `Object.prototype`
|
|
94
|
+
|
|
95
|
+
import { expect, use } from 'chai'; // Creates local variables `expect` and `use`; useful for plugin use
|
|
114
96
|
```
|
|
115
97
|
|
|
116
98
|
### Usage with Mocha
|
package/lib/chai/assertion.js
CHANGED
|
@@ -54,7 +54,7 @@ export function Assertion (obj, msg, ssfi, lockSsfi) {
|
|
|
54
54
|
util.flag(this, 'lockSsfi', lockSsfi);
|
|
55
55
|
util.flag(this, 'object', obj);
|
|
56
56
|
util.flag(this, 'message', msg);
|
|
57
|
-
util.flag(this, 'eql', config.deepEqual
|
|
57
|
+
util.flag(this, 'eql', config.deepEqual || util.eql);
|
|
58
58
|
|
|
59
59
|
return util.proxify(this);
|
|
60
60
|
}
|
|
@@ -239,6 +239,13 @@ Assertion.addProperty('all', function () {
|
|
|
239
239
|
flag(this, 'any', false);
|
|
240
240
|
});
|
|
241
241
|
|
|
242
|
+
const functionTypes = {
|
|
243
|
+
'function': ['function', 'asyncfunction', 'generatorfunction', 'asyncgeneratorfunction'],
|
|
244
|
+
'asyncfunction': ['asyncfunction', 'asyncgeneratorfunction'],
|
|
245
|
+
'generatorfunction': ['generatorfunction', 'asyncgeneratorfunction'],
|
|
246
|
+
'asyncgeneratorfunction': ['asyncgeneratorfunction']
|
|
247
|
+
}
|
|
248
|
+
|
|
242
249
|
/**
|
|
243
250
|
* ### .a(type[, msg])
|
|
244
251
|
*
|
|
@@ -298,18 +305,27 @@ Assertion.addProperty('all', function () {
|
|
|
298
305
|
* @namespace BDD
|
|
299
306
|
* @api public
|
|
300
307
|
*/
|
|
301
|
-
|
|
302
308
|
function an (type, msg) {
|
|
303
309
|
if (msg) flag(this, 'message', msg);
|
|
304
310
|
type = type.toLowerCase();
|
|
305
311
|
var obj = flag(this, 'object')
|
|
306
312
|
, article = ~[ 'a', 'e', 'i', 'o', 'u' ].indexOf(type.charAt(0)) ? 'an ' : 'a ';
|
|
307
313
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
314
|
+
const detectedType = _.type(obj).toLowerCase();
|
|
315
|
+
|
|
316
|
+
if (functionTypes['function'].includes(type)) {
|
|
317
|
+
this.assert(
|
|
318
|
+
functionTypes[type].includes(detectedType)
|
|
319
|
+
, 'expected #{this} to be ' + article + type
|
|
320
|
+
, 'expected #{this} not to be ' + article + type
|
|
321
|
+
);
|
|
322
|
+
} else {
|
|
323
|
+
this.assert(
|
|
324
|
+
type === detectedType
|
|
325
|
+
, 'expected #{this} to be ' + article + type
|
|
326
|
+
, 'expected #{this} not to be ' + article + type
|
|
327
|
+
);
|
|
328
|
+
}
|
|
313
329
|
}
|
|
314
330
|
|
|
315
331
|
Assertion.addChainableMethod('an', an);
|
|
@@ -672,6 +688,43 @@ Assertion.addProperty('true', function () {
|
|
|
672
688
|
);
|
|
673
689
|
});
|
|
674
690
|
|
|
691
|
+
/**
|
|
692
|
+
* ### .callable
|
|
693
|
+
*
|
|
694
|
+
* Asserts that the target a callable function.
|
|
695
|
+
*
|
|
696
|
+
* expect(console.log).to.be.callable;
|
|
697
|
+
*
|
|
698
|
+
* A custom error message can be given as the second argument to `expect`.
|
|
699
|
+
*
|
|
700
|
+
* expect('not a function', 'nooo why fail??').to.be.callable;
|
|
701
|
+
*
|
|
702
|
+
* @name callable
|
|
703
|
+
* @namespace BDD
|
|
704
|
+
* @api public
|
|
705
|
+
*/
|
|
706
|
+
Assertion.addProperty('callable', function () {
|
|
707
|
+
const val = flag(this, 'object')
|
|
708
|
+
const ssfi = flag(this, 'ssfi')
|
|
709
|
+
const message = flag(this, 'message')
|
|
710
|
+
const msg = message ? `${message}: ` : ''
|
|
711
|
+
const negate = flag(this, 'negate');
|
|
712
|
+
|
|
713
|
+
const assertionMessage = negate ?
|
|
714
|
+
`${msg}expected ${_.inspect(val)} not to be a callable function` :
|
|
715
|
+
`${msg}expected ${_.inspect(val)} to be a callable function`;
|
|
716
|
+
|
|
717
|
+
const isCallable = ['Function', 'AsyncFunction', 'GeneratorFunction', 'AsyncGeneratorFunction'].includes(_.type(val));
|
|
718
|
+
|
|
719
|
+
if ((isCallable && negate) || (!isCallable && !negate)) {
|
|
720
|
+
throw new AssertionError(
|
|
721
|
+
assertionMessage,
|
|
722
|
+
undefined,
|
|
723
|
+
ssfi
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
});
|
|
727
|
+
|
|
675
728
|
/**
|
|
676
729
|
* ### .false
|
|
677
730
|
*
|
|
@@ -8,6 +8,7 @@ import * as chai from '../../../index.js';
|
|
|
8
8
|
import {Assertion} from '../assertion.js';
|
|
9
9
|
import {flag, inspect} from '../utils/index.js';
|
|
10
10
|
import {AssertionError} from 'assertion-error';
|
|
11
|
+
import {type} from '../utils/type-detect.js';
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* ### assert(expression, message)
|
|
@@ -553,41 +554,39 @@ assert.isDefined = function (val, msg) {
|
|
|
553
554
|
};
|
|
554
555
|
|
|
555
556
|
/**
|
|
556
|
-
* ### .
|
|
557
|
+
* ### .isCallable(value, [message])
|
|
557
558
|
*
|
|
558
|
-
* Asserts that `value` is a function.
|
|
559
|
+
* Asserts that `value` is a callable function.
|
|
559
560
|
*
|
|
560
561
|
* function serveTea() { return 'cup of tea'; };
|
|
561
|
-
* assert.
|
|
562
|
+
* assert.isCallable(serveTea, 'great, we can have tea now');
|
|
562
563
|
*
|
|
563
|
-
* @name
|
|
564
|
+
* @name isCallable
|
|
564
565
|
* @param {Mixed} value
|
|
565
566
|
* @param {String} message
|
|
566
567
|
* @namespace Assert
|
|
567
568
|
* @api public
|
|
568
569
|
*/
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
};
|
|
570
|
+
assert.isCallable = function (val, msg) {
|
|
571
|
+
new Assertion(val, msg, assert.isCallable, true).is.callable;
|
|
572
|
+
}
|
|
573
573
|
|
|
574
574
|
/**
|
|
575
|
-
* ### .
|
|
575
|
+
* ### .isNotCallable(value, [message])
|
|
576
576
|
*
|
|
577
|
-
* Asserts that `value` is _not_ a function.
|
|
577
|
+
* Asserts that `value` is _not_ a callable function.
|
|
578
578
|
*
|
|
579
579
|
* var serveTea = [ 'heat', 'pour', 'sip' ];
|
|
580
|
-
* assert.
|
|
580
|
+
* assert.isNotCallable(serveTea, 'great, we have listed the steps');
|
|
581
581
|
*
|
|
582
|
-
* @name
|
|
582
|
+
* @name isNotCallable
|
|
583
583
|
* @param {Mixed} value
|
|
584
584
|
* @param {String} message
|
|
585
585
|
* @namespace Assert
|
|
586
586
|
* @api public
|
|
587
587
|
*/
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
new Assertion(val, msg, assert.isNotFunction, true).to.not.be.a('function');
|
|
588
|
+
assert.isNotCallable = function (val, msg) {
|
|
589
|
+
new Assertion(val, msg, assert.isNotCallable, true).is.not.callable;
|
|
591
590
|
};
|
|
592
591
|
|
|
593
592
|
/**
|
|
@@ -3104,4 +3103,6 @@ assert.isNotEmpty = function(val, msg) {
|
|
|
3104
3103
|
('isFrozen', 'frozen')
|
|
3105
3104
|
('isNotFrozen', 'notFrozen')
|
|
3106
3105
|
('isEmpty', 'empty')
|
|
3107
|
-
('isNotEmpty', 'notEmpty')
|
|
3106
|
+
('isNotEmpty', 'notEmpty')
|
|
3107
|
+
('isCallable', 'isFunction')
|
|
3108
|
+
('isNotCallable', 'isNotFunction')
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"Veselin Todorov <hi@vesln.com>",
|
|
19
19
|
"John Firebaugh <john.firebaugh@gmail.com>"
|
|
20
20
|
],
|
|
21
|
-
"version": "5.0.
|
|
21
|
+
"version": "5.0.2",
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|
|
24
24
|
"url": "https://github.com/chaijs/chai"
|
|
@@ -44,16 +44,15 @@
|
|
|
44
44
|
"assertion-error": "^2.0.1",
|
|
45
45
|
"check-error": "^2.0.0",
|
|
46
46
|
"deep-eql": "^5.0.1",
|
|
47
|
-
"loupe": "^3.
|
|
47
|
+
"loupe": "^3.1.0",
|
|
48
48
|
"pathval": "^2.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
52
|
-
"@web/dev-server-rollup": "^0.
|
|
53
|
-
"@web/test-runner": "^0.
|
|
54
|
-
"@web/test-runner-playwright": "^0.
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"mocha": "^8.3.0"
|
|
52
|
+
"@web/dev-server-rollup": "^0.6.1",
|
|
53
|
+
"@web/test-runner": "^0.18.0",
|
|
54
|
+
"@web/test-runner-playwright": "^0.11.0",
|
|
55
|
+
"esbuild": "^0.19.10",
|
|
56
|
+
"mocha": "^10.2.0"
|
|
58
57
|
}
|
|
59
58
|
}
|
package/bower.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chai",
|
|
3
|
-
"description": "BDD/TDD assertion library for node.js and the browser. Test framework agnostic.",
|
|
4
|
-
"license": "MIT",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"test",
|
|
7
|
-
"assertion",
|
|
8
|
-
"assert",
|
|
9
|
-
"testing",
|
|
10
|
-
"chai"
|
|
11
|
-
],
|
|
12
|
-
"main": "chai.js",
|
|
13
|
-
"ignore": [
|
|
14
|
-
"build",
|
|
15
|
-
"components",
|
|
16
|
-
"lib",
|
|
17
|
-
"node_modules",
|
|
18
|
-
"support",
|
|
19
|
-
"test",
|
|
20
|
-
"index.js",
|
|
21
|
-
"Makefile",
|
|
22
|
-
".*"
|
|
23
|
-
],
|
|
24
|
-
"dependencies": {},
|
|
25
|
-
"devDependencies": {}
|
|
26
|
-
}
|