Skip to content

Commit 4f1dd0f

Browse files
committed
Support NodeJS v.6.12.3+: check assert.throws against regexp
1 parent 6d552b4 commit 4f1dd0f

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

test/crypto.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,37 @@ describe("Crypto", () => {
1414
describe("#new Crypto", () => {
1515
it("with empty config", () => {
1616
assert.throws(() =>
17-
new Crypto({}), Error("Config not valid: paths should be an array of path element.")
17+
new Crypto({}), /Config not valid: paths should be an array of path element./
1818
);
1919
});
2020

2121
it("with string config", () => {
2222
assert.throws(() =>
23-
new Crypto(""), Error("Config not valid: config should be an object.")
23+
new Crypto(""), /Config not valid: config should be an object./
2424
);
2525
});
2626

2727
it("with wrong encoding", () => {
2828
let config = JSON.parse(JSON.stringify(testConfig));
2929
config["dataEncoding"] = "foo";
3030
assert.throws(() =>
31-
new Crypto(config), Error("Config not valid: dataEncoding should be 'hex' or 'base64'")
31+
new Crypto(config), /Config not valid: dataEncoding should be 'hex' or 'base64'/
3232
);
3333
});
3434

3535
it("with one property not defined", () => {
3636
let config = JSON.parse(JSON.stringify(testConfig));
3737
delete config["ivFieldName"];
3838
assert.throws(() =>
39-
new Crypto(config), Error("Config not valid: please check that all the properties are defined.")
39+
new Crypto(config), /Config not valid: please check that all the properties are defined./
4040
);
4141
});
4242

4343
it("with empty paths", () => {
4444
let config = JSON.parse(JSON.stringify(testConfig));
4545
config.paths = [];
4646
assert.throws(() =>
47-
new Crypto(config), Error("Config not valid: paths should be not empty.")
47+
new Crypto(config), /Config not valid: paths should be not empty./
4848
);
4949
});
5050

@@ -77,7 +77,7 @@ describe("Crypto", () => {
7777
let config = JSON.parse(JSON.stringify(testConfigHeader));
7878
delete config["ivHeaderName"];
7979
assert.throws(() =>
80-
new Crypto(config), Error("Config not valid: please check that all the properties are defined.")
80+
new Crypto(config), /Config not valid: please check that all the properties are defined./
8181
);
8282
});
8383
});
@@ -91,7 +91,7 @@ describe("Crypto", () => {
9191
it("with empty string", () => {
9292
assert.throws(() => {
9393
crypto.encryptData({data: ""});
94-
}, Error("Json not valid"));
94+
}, /Json not valid/);
9595
});
9696

9797
it("with valid object, iv and secretKey", () => {
@@ -127,13 +127,13 @@ describe("Crypto", () => {
127127
it("with null", () => {
128128
assert.throws(() => {
129129
crypto.decryptData(null);
130-
}, Error("Input not valid"));
130+
}, /Input not valid/);
131131
});
132132

133133
it("with empty string", () => {
134134
assert.throws(() => {
135135
crypto.decryptData("");
136-
}, Error("Input not valid"));
136+
}, /Input not valid/);
137137
});
138138

139139
it("with valid object", () => {
@@ -149,7 +149,7 @@ describe("Crypto", () => {
149149
let generateSecretKey = Crypto.__get__("generateSecretKey");
150150
assert.throws(() => {
151151
generateSecretKey("ABC");
152-
}, Error("Unsupported symmetric algorithm"));
152+
}, /Unsupported symmetric algorithm/);
153153
});
154154
});
155155

@@ -158,7 +158,7 @@ describe("Crypto", () => {
158158
let loadPrivateKey = Crypto.__get__("loadPrivateKey");
159159
assert.throws(() => {
160160
loadPrivateKey("./test/res/empty.key");
161-
}, Error("Private key content not valid"));
161+
}, /Private key content not valid/);
162162
});
163163
});
164164

@@ -167,7 +167,7 @@ describe("Crypto", () => {
167167
let readPublicCertificate = Crypto.__get__("readPublicCertificate");
168168
assert.throws(() => {
169169
readPublicCertificate("./test/res/empty.key");
170-
}, Error("Public certificate content is not valid"));
170+
}, /Public certificate content is not valid/);
171171
});
172172
});
173173

@@ -177,19 +177,19 @@ describe("Crypto", () => {
177177
it("not valid key", () => {
178178
assert.throws(() => {
179179
getPrivateKey("./test/res/empty.key");
180-
}, Error("p12 keystore content is empty"));
180+
}, /p12 keystore content is empty/);
181181
});
182182

183183
it("empty alias", () => {
184184
assert.throws(() => {
185185
getPrivateKey("./test/res/test_key_container.p12");
186-
}, Error("Key alias is not set"));
186+
}, /Key alias is not set/);
187187
});
188188

189189
it("empty password", () => {
190190
assert.throws(() => {
191191
getPrivateKey("./test/res/test_key_container.p12", "keyalias");
192-
}, Error("Keystore password is not set"));
192+
}, /Keystore password is not set/);
193193
});
194194

195195
it("valid p12", () => {
@@ -200,7 +200,7 @@ describe("Crypto", () => {
200200
it("valid p12, alias not found", () => {
201201
assert.throws(() => {
202202
getPrivateKey("./test/res/test_key_container.p12", "mykeyalias1", "Password1");
203-
}, Error("No key found for alias [mykeyalias1]"));
203+
}, /No key found for alias \[mykeyalias1\]/);
204204
});
205205
});
206206

test/mcapi-service.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ describe("MC API Service", () => {
99
it("when null", () => {
1010
assert.throws(() => {
1111
new MCService(null, testConfig);
12-
}, Error("service should be a valid OpenAPI client."));
12+
}, /service should be a valid OpenAPI client./);
1313
});
1414

1515
it("with not right openapi client", () => {
1616
assert.throws(() => {
1717
new MCService({}, testConfig);
18-
}, Error("service should be a valid OpenAPI client."));
18+
}, /service should be a valid OpenAPI client./);
1919
assert.throws(() => {
2020
new MCService({ApiClient: {}}, testConfig);
21-
}, Error("service should be a valid OpenAPI client."));
21+
}, /service should be a valid OpenAPI client./);
2222
});
2323

2424
it("callApi intercepted", function (done) {

0 commit comments

Comments
 (0)