@webex/test-helper-chai 2.59.2 → 2.59.3-next.1

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.
@@ -1,158 +1,158 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- /* eslint-disable no-invalid-this */
6
-
7
- const checkError = require('check-error');
8
- const file = require('@webex/test-helper-file');
9
-
10
- const schemas = require('./schemas');
11
- const primitives = require('./primitives');
12
-
13
- /**
14
- * @param {Object} chai
15
- * @returns {undefined}
16
- */
17
- module.exports = function registerAssertions(chai) {
18
- const {Assertion} = chai;
19
-
20
- // The follow assertion is adapted from chai-as-promised as that library is no
21
- // longer compatible with IE 11
22
- Assertion.addMethod('rejectedWith', function expectedRejection(errorLike, errMsgMatcher, msg) {
23
- const {assert} = chai;
24
- const {flag} = chai.util;
25
-
26
- if (msg) {
27
- flag(this, 'message', msg);
28
- }
29
-
30
- const promise = this.then ? this : this._obj;
31
-
32
- return promise.then(
33
- (actual) => {
34
- assert(
35
- false,
36
- 'expected #{this} to be rejected but it was fulfilled with #{act}',
37
- null,
38
- errorLike && errorLike.toString(),
39
- actual
40
- );
41
-
42
- return actual;
43
- },
44
- // complexity is result of basic ternaries
45
- // eslint-disable-next-line complexity
46
- function onReject(reason) {
47
- if (errorLike) {
48
- if (errorLike instanceof Error) {
49
- if (!checkError.compatibleInstance(reason, errorLike)) {
50
- this.assert(
51
- false,
52
- 'expected #{this} to be rejected with #{exp} but was rejected with #{act}',
53
- null,
54
- errorLike.toString(),
55
- reason.toString()
56
- );
57
- }
58
- }
59
-
60
- if (!checkError.compatibleConstructor(reason, errorLike)) {
61
- this.assert(
62
- false,
63
- 'expected #{this} to be rejected with #{exp} but was rejected with #{act}',
64
- null,
65
- errorLike instanceof Error
66
- ? errorLike.toString()
67
- : errorLike && checkError.getConstructorName(errorLike),
68
- reason instanceof Error
69
- ? reason.toString()
70
- : reason && checkError.getConstructorName(reason)
71
- );
72
- }
73
- }
74
-
75
- if (reason && errMsgMatcher) {
76
- let placeholder = 'including';
77
-
78
- if (errMsgMatcher instanceof RegExp) {
79
- placeholder = 'matching';
80
- }
81
-
82
- if (!checkError.compatibleMessage(reason, errMsgMatcher)) {
83
- this.assert(
84
- false,
85
- `expected #{this} to be be rejected with error ${placeholder} #{exp} but got #{act}`,
86
- null,
87
- errMsgMatcher,
88
- checkError.getMessage(reason)
89
- );
90
- }
91
- }
92
-
93
- return reason;
94
- }
95
- );
96
- });
97
-
98
- chai.assert.isRejected = function isRejected(promise, errorLike, errMsgMatcher, msg) {
99
- if (typeof errorLike === 'string' || errorLike instanceof RegExp) {
100
- errMsgMatcher = errorLike;
101
- errorLike = null;
102
- }
103
-
104
- return new Assertion(promise, msg, chai.assert.isRejected, true).to.be.rejectedWith(
105
- errorLike,
106
- errMsgMatcher
107
- );
108
- };
109
-
110
- /* eslint no-unused-expressions: [0] */
111
-
112
- Assertion.addMethod('statusCode', function expectStatusCode(statusCode) {
113
- this.assert(
114
- (this._obj.statusCode || this._obj) === statusCode,
115
- `expected #{this} to have an HTTP Status Code of ${statusCode}`,
116
- `expected #{this} to not have an HTTP Status Code of ${statusCode}`
117
- );
118
- });
119
-
120
- chai.assert.statusCode = function assertStatusCode(obj, statusCode, msg) {
121
- new Assertion(obj, msg).to.have.statusCode(statusCode);
122
- };
123
-
124
- Assertion.addProperty('blobLike', function blobLike() {
125
- this.assert(
126
- file.isBlobLike(this._obj),
127
- 'expected #{this} to be a Buffer (nodejs) or Blob (browser)',
128
- 'expected #{this} not to be a Buffer (nodejs) or Blob (browser)'
129
- );
130
- });
131
-
132
- Assertion.addProperty('bufferLike', function bufferLike() {
133
- this.assert(
134
- file.isBufferLike(this._obj),
135
- 'expected #{this} to be a Buffer (nodejs) or ArrayBuffer (browser)',
136
- 'expected #{this} not to be a Buffer (nodejs) or ArrayBuffer (browser)'
137
- );
138
- });
139
-
140
- chai.assert.isBlobLike = function isBlobLike(obj, msg) {
141
- new Assertion(obj, msg).to.be.blobLike;
142
- };
143
-
144
- chai.assert.isNotBlobLike = function isNotBlobLike(obj, msg) {
145
- new Assertion(obj, msg).not.to.be.blobLike;
146
- };
147
-
148
- chai.assert.isBufferLike = function isBufferLike(obj, msg) {
149
- new Assertion(obj, msg).to.be.bufferLike;
150
- };
151
-
152
- chai.assert.isNotBufferLike = function isNotBufferLike(obj, msg) {
153
- new Assertion(obj, msg).not.to.be.bufferLike;
154
- };
155
-
156
- primitives(chai);
157
- schemas(chai);
158
- };
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint-disable no-invalid-this */
6
+
7
+ const checkError = require('check-error');
8
+ const file = require('@webex/test-helper-file');
9
+
10
+ const schemas = require('./schemas');
11
+ const primitives = require('./primitives');
12
+
13
+ /**
14
+ * @param {Object} chai
15
+ * @returns {undefined}
16
+ */
17
+ module.exports = function registerAssertions(chai) {
18
+ const {Assertion} = chai;
19
+
20
+ // The follow assertion is adapted from chai-as-promised as that library is no
21
+ // longer compatible with IE 11
22
+ Assertion.addMethod('rejectedWith', function expectedRejection(errorLike, errMsgMatcher, msg) {
23
+ const {assert} = chai;
24
+ const {flag} = chai.util;
25
+
26
+ if (msg) {
27
+ flag(this, 'message', msg);
28
+ }
29
+
30
+ const promise = this.then ? this : this._obj;
31
+
32
+ return promise.then(
33
+ (actual) => {
34
+ assert(
35
+ false,
36
+ 'expected #{this} to be rejected but it was fulfilled with #{act}',
37
+ null,
38
+ errorLike && errorLike.toString(),
39
+ actual
40
+ );
41
+
42
+ return actual;
43
+ },
44
+ // complexity is result of basic ternaries
45
+ // eslint-disable-next-line complexity
46
+ function onReject(reason) {
47
+ if (errorLike) {
48
+ if (errorLike instanceof Error) {
49
+ if (!checkError.compatibleInstance(reason, errorLike)) {
50
+ this.assert(
51
+ false,
52
+ 'expected #{this} to be rejected with #{exp} but was rejected with #{act}',
53
+ null,
54
+ errorLike.toString(),
55
+ reason.toString()
56
+ );
57
+ }
58
+ }
59
+
60
+ if (!checkError.compatibleConstructor(reason, errorLike)) {
61
+ this.assert(
62
+ false,
63
+ 'expected #{this} to be rejected with #{exp} but was rejected with #{act}',
64
+ null,
65
+ errorLike instanceof Error
66
+ ? errorLike.toString()
67
+ : errorLike && checkError.getConstructorName(errorLike),
68
+ reason instanceof Error
69
+ ? reason.toString()
70
+ : reason && checkError.getConstructorName(reason)
71
+ );
72
+ }
73
+ }
74
+
75
+ if (reason && errMsgMatcher) {
76
+ let placeholder = 'including';
77
+
78
+ if (errMsgMatcher instanceof RegExp) {
79
+ placeholder = 'matching';
80
+ }
81
+
82
+ if (!checkError.compatibleMessage(reason, errMsgMatcher)) {
83
+ this.assert(
84
+ false,
85
+ `expected #{this} to be be rejected with error ${placeholder} #{exp} but got #{act}`,
86
+ null,
87
+ errMsgMatcher,
88
+ checkError.getMessage(reason)
89
+ );
90
+ }
91
+ }
92
+
93
+ return reason;
94
+ }
95
+ );
96
+ });
97
+
98
+ chai.assert.isRejected = function isRejected(promise, errorLike, errMsgMatcher, msg) {
99
+ if (typeof errorLike === 'string' || errorLike instanceof RegExp) {
100
+ errMsgMatcher = errorLike;
101
+ errorLike = null;
102
+ }
103
+
104
+ return new Assertion(promise, msg, chai.assert.isRejected, true).to.be.rejectedWith(
105
+ errorLike,
106
+ errMsgMatcher
107
+ );
108
+ };
109
+
110
+ /* eslint no-unused-expressions: [0] */
111
+
112
+ Assertion.addMethod('statusCode', function expectStatusCode(statusCode) {
113
+ this.assert(
114
+ (this._obj.statusCode || this._obj) === statusCode,
115
+ `expected #{this} to have an HTTP Status Code of ${statusCode}`,
116
+ `expected #{this} to not have an HTTP Status Code of ${statusCode}`
117
+ );
118
+ });
119
+
120
+ chai.assert.statusCode = function assertStatusCode(obj, statusCode, msg) {
121
+ new Assertion(obj, msg).to.have.statusCode(statusCode);
122
+ };
123
+
124
+ Assertion.addProperty('blobLike', function blobLike() {
125
+ this.assert(
126
+ file.isBlobLike(this._obj),
127
+ 'expected #{this} to be a Buffer (nodejs) or Blob (browser)',
128
+ 'expected #{this} not to be a Buffer (nodejs) or Blob (browser)'
129
+ );
130
+ });
131
+
132
+ Assertion.addProperty('bufferLike', function bufferLike() {
133
+ this.assert(
134
+ file.isBufferLike(this._obj),
135
+ 'expected #{this} to be a Buffer (nodejs) or ArrayBuffer (browser)',
136
+ 'expected #{this} not to be a Buffer (nodejs) or ArrayBuffer (browser)'
137
+ );
138
+ });
139
+
140
+ chai.assert.isBlobLike = function isBlobLike(obj, msg) {
141
+ new Assertion(obj, msg).to.be.blobLike;
142
+ };
143
+
144
+ chai.assert.isNotBlobLike = function isNotBlobLike(obj, msg) {
145
+ new Assertion(obj, msg).not.to.be.blobLike;
146
+ };
147
+
148
+ chai.assert.isBufferLike = function isBufferLike(obj, msg) {
149
+ new Assertion(obj, msg).to.be.bufferLike;
150
+ };
151
+
152
+ chai.assert.isNotBufferLike = function isNotBufferLike(obj, msg) {
153
+ new Assertion(obj, msg).not.to.be.bufferLike;
154
+ };
155
+
156
+ primitives(chai);
157
+ schemas(chai);
158
+ };
@@ -1,71 +1,71 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- /* eslint-disable no-invalid-this */
6
- /* eslint-disable func-names */
7
-
8
- const shouldToAssert = require('./should-to-assert');
9
-
10
- /**
11
- * @param {Object} chai
12
- * @returns {undefined}
13
- */
14
- module.exports = function (chai) {
15
- const {Assertion, assert} = chai;
16
-
17
- /* eslint no-unused-expressions: [0] */
18
-
19
- const uuidPattern = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/;
20
- const emailPattern = /^[^\s]+?@[^\s]+?$/;
21
-
22
- Assertion.addProperty('hydraId', function () {
23
- assert.isString(this._obj);
24
- assert.notMatch(this._obj, uuidPattern);
25
- });
26
-
27
- Assertion.addProperty('uuid', function () {
28
- assert.isString(this._obj);
29
- assert.match(this._obj, uuidPattern);
30
- });
31
-
32
- Assertion.addProperty('email', function () {
33
- assert.isString(this._obj);
34
- assert.match(this._obj, emailPattern);
35
- });
36
-
37
- Assertion.addProperty('isoDate', function () {
38
- assert.isString(this._obj);
39
- assert.isNotNumber(this._obj);
40
- assert.notEqual(parseInt(this._obj, 10).toString(), this._obj);
41
- });
42
-
43
- Assertion.addMethod('properties', function (properties) {
44
- properties.forEach((property) => {
45
- assert.property(this._obj, property);
46
- });
47
- });
48
-
49
- chai.assert.properties = function (obj, properties, msg) {
50
- new Assertion(obj, msg).to.have.properties(properties);
51
- };
52
-
53
- Assertion.addMethod('strictProperties', function (properties) {
54
- properties.forEach((property) => {
55
- assert.property(this._obj, property);
56
- });
57
-
58
- assert.deepEqual(Object.keys(this._obj).sort(), properties.sort());
59
- });
60
-
61
- chai.assert.strictProperties = function (obj, properties, msg) {
62
- new Assertion(obj, msg).to.have.strictProperties(properties);
63
- };
64
-
65
- shouldToAssert(chai, {
66
- hydraId: 'isHydraID',
67
- uuid: 'isUUID',
68
- email: 'isEmail',
69
- isoDate: 'isISODate',
70
- });
71
- };
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint-disable no-invalid-this */
6
+ /* eslint-disable func-names */
7
+
8
+ const shouldToAssert = require('./should-to-assert');
9
+
10
+ /**
11
+ * @param {Object} chai
12
+ * @returns {undefined}
13
+ */
14
+ module.exports = function (chai) {
15
+ const {Assertion, assert} = chai;
16
+
17
+ /* eslint no-unused-expressions: [0] */
18
+
19
+ const uuidPattern = /^[a-f\d]{8}(?:-[a-f\d]{4}){3}-[a-f\d]{12}$/;
20
+ const emailPattern = /^[^\s]+?@[^\s]+?$/;
21
+
22
+ Assertion.addProperty('hydraId', function () {
23
+ assert.isString(this._obj);
24
+ assert.notMatch(this._obj, uuidPattern);
25
+ });
26
+
27
+ Assertion.addProperty('uuid', function () {
28
+ assert.isString(this._obj);
29
+ assert.match(this._obj, uuidPattern);
30
+ });
31
+
32
+ Assertion.addProperty('email', function () {
33
+ assert.isString(this._obj);
34
+ assert.match(this._obj, emailPattern);
35
+ });
36
+
37
+ Assertion.addProperty('isoDate', function () {
38
+ assert.isString(this._obj);
39
+ assert.isNotNumber(this._obj);
40
+ assert.notEqual(parseInt(this._obj, 10).toString(), this._obj);
41
+ });
42
+
43
+ Assertion.addMethod('properties', function (properties) {
44
+ properties.forEach((property) => {
45
+ assert.property(this._obj, property);
46
+ });
47
+ });
48
+
49
+ chai.assert.properties = function (obj, properties, msg) {
50
+ new Assertion(obj, msg).to.have.properties(properties);
51
+ };
52
+
53
+ Assertion.addMethod('strictProperties', function (properties) {
54
+ properties.forEach((property) => {
55
+ assert.property(this._obj, property);
56
+ });
57
+
58
+ assert.deepEqual(Object.keys(this._obj).sort(), properties.sort());
59
+ });
60
+
61
+ chai.assert.strictProperties = function (obj, properties, msg) {
62
+ new Assertion(obj, msg).to.have.strictProperties(properties);
63
+ };
64
+
65
+ shouldToAssert(chai, {
66
+ hydraId: 'isHydraID',
67
+ uuid: 'isUUID',
68
+ email: 'isEmail',
69
+ isoDate: 'isISODate',
70
+ });
71
+ };