@opra/testing 1.12.6 → 1.13.0
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/cjs/api-expect/api-expect-base.js +2 -1
- package/cjs/api-expect/api-expect-object.js +3 -2
- package/cjs/api-expect/api-expect.js +16 -15
- package/cjs/utils/object-matches.util.js +4 -3
- package/esm/api-expect/api-expect-base.js +1 -0
- package/esm/api-expect/api-expect-object.js +1 -0
- package/esm/api-expect/api-expect.js +1 -0
- package/esm/utils/object-matches.util.js +1 -0
- package/package.json +3 -3
- package/types/api-expect/api-expect-base.d.ts +1 -1
- package/types/jest-extend/common.extend.d.ts +15 -0
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApiExpectBase = void 0;
|
|
4
4
|
require("../jest-extend/index.js");
|
|
5
|
+
const expect_1 = require("expect");
|
|
5
6
|
class ApiExpectBase {
|
|
6
7
|
constructor(response, isNot) {
|
|
7
8
|
this.response = response;
|
|
8
9
|
this.isNot = isNot;
|
|
9
10
|
}
|
|
10
11
|
_expect(expected) {
|
|
11
|
-
const out = expect(expected);
|
|
12
|
+
const out = (0, expect_1.expect)(expected);
|
|
12
13
|
if (this.isNot)
|
|
13
14
|
return out.not;
|
|
14
15
|
return out;
|
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const type_is_1 = tslib_1.__importDefault(require("@browsery/type-is"));
|
|
6
6
|
const objects_1 = require("@jsopen/objects");
|
|
7
7
|
const common_1 = require("@opra/common");
|
|
8
|
+
const expect_1 = require("expect");
|
|
8
9
|
const api_expect_base_js_1 = require("./api-expect-base.js");
|
|
9
10
|
class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
|
|
10
11
|
get not() {
|
|
@@ -22,7 +23,7 @@ class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
|
|
|
22
23
|
])
|
|
23
24
|
? this.response.body.payload
|
|
24
25
|
: this.response.body;
|
|
25
|
-
this._expect(data).toEqual(expect.objectContaining(expected));
|
|
26
|
+
this._expect(data).toEqual(expect_1.expect.objectContaining(expected));
|
|
26
27
|
}
|
|
27
28
|
catch (e) {
|
|
28
29
|
Error.captureStackTrace(e, this.toMatch);
|
|
@@ -42,7 +43,7 @@ class ApiExpectObject extends api_expect_base_js_1.ApiExpectBase {
|
|
|
42
43
|
])
|
|
43
44
|
? this.response.body.payload
|
|
44
45
|
: this.response.body;
|
|
45
|
-
this._expect(Object.keys(data)).toEqual(expect.arrayContaining(fields));
|
|
46
|
+
this._expect(Object.keys(data)).toEqual(expect_1.expect.arrayContaining(fields));
|
|
46
47
|
}
|
|
47
48
|
catch (e) {
|
|
48
49
|
Error.captureStackTrace(e, this.toContainFields);
|
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
require("../jest-extend/index.js");
|
|
6
6
|
const common_1 = require("@opra/common");
|
|
7
7
|
const ansi_colors_1 = tslib_1.__importDefault(require("ansi-colors"));
|
|
8
|
+
const expect_1 = require("expect");
|
|
8
9
|
const api_expect_base_js_1 = require("./api-expect-base.js");
|
|
9
10
|
const api_expect_collection_js_1 = require("./api-expect-collection.js");
|
|
10
11
|
const api_expect_error_js_1 = require("./api-expect-error.js");
|
|
@@ -20,11 +21,11 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
20
21
|
try {
|
|
21
22
|
msg += `Status code do not match. `;
|
|
22
23
|
if (status) {
|
|
23
|
-
expect(this.response.status).toEqual(status);
|
|
24
|
+
(0, expect_1.expect)(this.response.status).toEqual(status);
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
|
-
expect(this.response.status).toBeGreaterThanOrEqual(200);
|
|
27
|
-
expect(this.response.status).toBeLessThan(400);
|
|
27
|
+
(0, expect_1.expect)(this.response.status).toBeGreaterThanOrEqual(200);
|
|
28
|
+
(0, expect_1.expect)(this.response.status).toBeLessThan(400);
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
31
|
catch (e) {
|
|
@@ -60,11 +61,11 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
60
61
|
try {
|
|
61
62
|
msg += `Status code do not match. `;
|
|
62
63
|
if (status) {
|
|
63
|
-
expect(this.response.status).toEqual(status);
|
|
64
|
+
(0, expect_1.expect)(this.response.status).toEqual(status);
|
|
64
65
|
}
|
|
65
66
|
else {
|
|
66
|
-
expect(this.response.status).toBeGreaterThanOrEqual(400);
|
|
67
|
-
expect(this.response.status).toBeLessThanOrEqual(599);
|
|
67
|
+
(0, expect_1.expect)(this.response.status).toBeGreaterThanOrEqual(400);
|
|
68
|
+
(0, expect_1.expect)(this.response.status).toBeLessThanOrEqual(599);
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
catch (e) {
|
|
@@ -98,12 +99,12 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
98
99
|
let msg = '';
|
|
99
100
|
try {
|
|
100
101
|
msg = 'Content-Type header value is not valid. ';
|
|
101
|
-
expect(this.response.contentType).toEqual('application/opra.response+json');
|
|
102
|
+
(0, expect_1.expect)(this.response.contentType).toEqual('application/opra.response+json');
|
|
102
103
|
msg = 'Type of response "body" is not valid. ';
|
|
103
|
-
expect(typeof this.response.body).toEqual('object');
|
|
104
|
+
(0, expect_1.expect)(typeof this.response.body).toEqual('object');
|
|
104
105
|
msg = 'Type of "payload" is not an Array. ';
|
|
105
106
|
const payload = this.response.body.payload;
|
|
106
|
-
expect(Array.isArray(payload) ? 'array' : typeof payload).toEqual('array');
|
|
107
|
+
(0, expect_1.expect)(Array.isArray(payload) ? 'array' : typeof payload).toEqual('array');
|
|
107
108
|
}
|
|
108
109
|
catch (e) {
|
|
109
110
|
e.message =
|
|
@@ -122,12 +123,12 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
122
123
|
let msg = '';
|
|
123
124
|
try {
|
|
124
125
|
msg = 'Content-Type header value is not valid. ';
|
|
125
|
-
expect(this.response.contentType).toEqual(contentType || common_1.MimeTypes.opra_response_json);
|
|
126
|
+
(0, expect_1.expect)(this.response.contentType).toEqual(contentType || common_1.MimeTypes.opra_response_json);
|
|
126
127
|
msg = 'Type of response "body" is not valid. ';
|
|
127
|
-
expect(typeof this.response.body).toEqual('object');
|
|
128
|
+
(0, expect_1.expect)(typeof this.response.body).toEqual('object');
|
|
128
129
|
msg = 'Type of "payload" is not an Object. ';
|
|
129
130
|
const payload = this.response.body.payload;
|
|
130
|
-
expect(typeof payload).toEqual('object');
|
|
131
|
+
(0, expect_1.expect)(typeof payload).toEqual('object');
|
|
131
132
|
}
|
|
132
133
|
catch (e) {
|
|
133
134
|
e.message = "Api didn't returned an Object. " + msg + '\n\n' + e.message;
|
|
@@ -145,12 +146,12 @@ class ApiExpect extends api_expect_base_js_1.ApiExpectBase {
|
|
|
145
146
|
let msg = '';
|
|
146
147
|
try {
|
|
147
148
|
msg = 'Content-Type header value is not valid. ';
|
|
148
|
-
expect(this.response.contentType).toEqual(common_1.MimeTypes.opra_response_json);
|
|
149
|
+
(0, expect_1.expect)(this.response.contentType).toEqual(common_1.MimeTypes.opra_response_json);
|
|
149
150
|
msg = 'Type of response "body" is not valid. ';
|
|
150
|
-
expect(typeof this.response.body).toEqual('object');
|
|
151
|
+
(0, expect_1.expect)(typeof this.response.body).toEqual('object');
|
|
151
152
|
msg = 'The response has payload. ';
|
|
152
153
|
const payload = this.response.body.payload;
|
|
153
|
-
expect(typeof payload).toEqual('undefined');
|
|
154
|
+
(0, expect_1.expect)(typeof payload).toEqual('undefined');
|
|
154
155
|
}
|
|
155
156
|
catch (e) {
|
|
156
157
|
e.message =
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.objectMatches = objectMatches;
|
|
4
|
+
const expect_1 = require("expect");
|
|
4
5
|
function objectMatches(received, expected) {
|
|
5
6
|
_objectMatches(received, expected, '');
|
|
6
7
|
}
|
|
7
8
|
function _objectMatches(received, expected, path) {
|
|
8
9
|
if (typeof received !== typeof expected)
|
|
9
|
-
expect(typeof received).toStrictEqual('object');
|
|
10
|
+
(0, expect_1.expect)(typeof received).toStrictEqual('object');
|
|
10
11
|
const keys = Object.keys(expected);
|
|
11
12
|
for (const k of keys) {
|
|
12
13
|
const rv = received[k];
|
|
13
14
|
const ev = expected[k];
|
|
14
15
|
if (ev instanceof RegExp) {
|
|
15
16
|
try {
|
|
16
|
-
expect(rv).toMatch(ev);
|
|
17
|
+
(0, expect_1.expect)(rv).toMatch(ev);
|
|
17
18
|
}
|
|
18
19
|
catch {
|
|
19
20
|
throw new Error(`Property "${k}" does not match`);
|
|
@@ -24,7 +25,7 @@ function _objectMatches(received, expected, path) {
|
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
26
27
|
try {
|
|
27
|
-
expect(rv).toEqual(ev);
|
|
28
|
+
(0, expect_1.expect)(rv).toEqual(ev);
|
|
28
29
|
}
|
|
29
30
|
catch {
|
|
30
31
|
throw new Error(`Property "${k}" does not match`);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import typeIs from '@browsery/type-is';
|
|
2
2
|
import { omitNullish } from '@jsopen/objects';
|
|
3
3
|
import { MimeTypes } from '@opra/common';
|
|
4
|
+
import { expect } from 'expect';
|
|
4
5
|
import { ApiExpectBase } from './api-expect-base.js';
|
|
5
6
|
export class ApiExpectObject extends ApiExpectBase {
|
|
6
7
|
get not() {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import '../jest-extend/index.js';
|
|
2
2
|
import { MimeTypes } from '@opra/common';
|
|
3
3
|
import colors from 'ansi-colors';
|
|
4
|
+
import { expect } from 'expect';
|
|
4
5
|
import { ApiExpectBase } from './api-expect-base.js';
|
|
5
6
|
import { ApiExpectCollection } from './api-expect-collection.js';
|
|
6
7
|
import { ApiExpectError } from './api-expect-error.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/testing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
4
4
|
"description": "Opra testing package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"tslib": "^2.8.1"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@opra/client": "^1.
|
|
16
|
-
"@opra/common": "^1.
|
|
15
|
+
"@opra/client": "^1.13.0",
|
|
16
|
+
"@opra/common": "^1.13.0",
|
|
17
17
|
"expect": "^29.0.0 || ^30.0.0",
|
|
18
18
|
"jest-matcher-utils": "^29.0.0 || ^30.0.0"
|
|
19
19
|
},
|
|
@@ -4,5 +4,5 @@ export declare class ApiExpectBase {
|
|
|
4
4
|
readonly response: HttpResponse;
|
|
5
5
|
protected readonly isNot?: boolean;
|
|
6
6
|
constructor(response: HttpResponse, isNot?: boolean);
|
|
7
|
-
protected _expect(expected: any):
|
|
7
|
+
protected _expect(expected: any): import("expect").Matchers<void, any>;
|
|
8
8
|
}
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
declare module 'expect' {
|
|
2
|
+
interface Matchers<R> {
|
|
3
|
+
toBeArray(): any;
|
|
4
|
+
toBeGreaterThanAny(expected: number | bigint | string | Date): any;
|
|
5
|
+
toBeGreaterThanOrEqualAny(expected: number | bigint | string | Date): any;
|
|
6
|
+
toBeLessThanAny(expected: number | bigint | string | Date): any;
|
|
7
|
+
toBeLessThanOrEqualAny(expected: number | bigint | string | Date): any;
|
|
8
|
+
}
|
|
9
|
+
interface InverseAsymmetricMatchers {
|
|
10
|
+
toBeGreaterThanAny(expected: number | bigint | string | Date): any;
|
|
11
|
+
toBeGreaterThanOrEqualAny(expected: number | bigint | string | Date): any;
|
|
12
|
+
toBeLessThanAny(expected: number | bigint | string | Date): any;
|
|
13
|
+
toBeLessThanOrEqualAny(expected: number | bigint | string | Date): any;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
1
16
|
declare global {
|
|
2
17
|
namespace jest {
|
|
3
18
|
interface Matchers<R> {
|