Skip to content

Commit a80765e

Browse files
authored
fix(init): throw accurate error with falsy appId/appKey (#509)
1 parent c824372 commit a80765e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ AV.init = function init(options, ...params) {
8181
realtime,
8282
} = options;
8383
if (AV.applicationId) throw new Error('SDK is already initialized.');
84+
if (!appId) throw new TypeError('appId must be a string');
85+
if (!appKey) throw new TypeError('appKey must be a string');
8486
if (process.env.CLIENT_PLATFORM && masterKey) console.warn('MasterKey is not supposed to be used in browser.');
8587
AV._config.applicationId = appId;
8688
AV._config.applicationKey = appKey;

test/av.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
describe('AV.init', () => {
2+
before(function() {
3+
this.originalAppId = AV.applicationId;
4+
AV.applicationId = undefined;
5+
});
6+
7+
after(function() {
8+
AV.applicationId = this.originalAppId;
9+
});
10+
11+
it('param check', () => {
12+
(() => AV.init()).should.throw(/must be a string/);
13+
(() => AV.init('aaa')).should.throw(/must be a string/);
14+
(() => AV.init('', '')).should.throw(/must be a string/);
15+
});
16+
});
17+
18+
119
describe('AV utils', () => {
220
describe('_encode', () => {
321
it('should be pure', () => {

0 commit comments

Comments
 (0)