Skip to content

Commit 9074a0b

Browse files
committed
Update tests so they dont leverage var, but let and const
With jasmine 3.0, the randomization engine was making the test fails because of the scope of `var`
1 parent 996fe96 commit 9074a0b

File tree

76 files changed

+2659
-2659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2659
-2659
lines changed

spec/.eslintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"arrayContains": true
2929
},
3030
"rules": {
31-
"no-console": [0]
31+
"no-console": [0],
32+
"no-var": "error"
3233
}
3334
}

spec/AccountLockoutPolicy.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const Config = require("../src/Config");
44

5-
var loginWithWrongCredentialsShouldFail = function(username, password) {
5+
const loginWithWrongCredentialsShouldFail = function(username, password) {
66
return new Promise((resolve, reject) => {
77
Parse.User.logIn(username, password)
88
.then(() => reject('login should have failed'))
@@ -16,7 +16,7 @@ var loginWithWrongCredentialsShouldFail = function(username, password) {
1616
});
1717
};
1818

19-
var isAccountLockoutError = function(username, password, duration, waitTime) {
19+
const isAccountLockoutError = function(username, password, duration, waitTime) {
2020
return new Promise((resolve, reject) => {
2121
setTimeout(() => {
2222
Parse.User.logIn(username, password)
@@ -40,7 +40,7 @@ describe("Account Lockout Policy: ", () => {
4040
publicServerURL: 'http://localhost:1337/1',
4141
})
4242
.then(() => {
43-
var user = new Parse.User();
43+
const user = new Parse.User();
4444
user.setUsername('username1');
4545
user.setPassword('password');
4646
return user.signUp(null);
@@ -215,7 +215,7 @@ describe("Account Lockout Policy: ", () => {
215215
publicServerURL: "http://localhost:8378/1"
216216
})
217217
.then(() => {
218-
var user = new Parse.User();
218+
const user = new Parse.User();
219219
user.setUsername("username2");
220220
user.setPassword("failedLoginAttemptsThreshold");
221221
return user.signUp();
@@ -248,7 +248,7 @@ describe("Account Lockout Policy: ", () => {
248248
publicServerURL: "http://localhost:8378/1"
249249
})
250250
.then(() => {
251-
var user = new Parse.User();
251+
const user = new Parse.User();
252252
user.setUsername("username3");
253253
user.setPassword("failedLoginAttemptsThreshold");
254254
return user.signUp();
@@ -285,7 +285,7 @@ describe("Account Lockout Policy: ", () => {
285285
publicServerURL: "http://localhost:8378/1"
286286
})
287287
.then(() => {
288-
var user = new Parse.User();
288+
const user = new Parse.User();
289289
user.setUsername("username4");
290290
user.setPassword("correct password");
291291
return user.signUp();

spec/AdaptableController.spec.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11

2-
var AdaptableController = require("../src/Controllers/AdaptableController").AdaptableController;
3-
var FilesAdapter = require("../src/Adapters/Files/FilesAdapter").default;
4-
var FilesController = require("../src/Controllers/FilesController").FilesController;
2+
const AdaptableController = require("../src/Controllers/AdaptableController").AdaptableController;
3+
const FilesAdapter = require("../src/Adapters/Files/FilesAdapter").default;
4+
const FilesController = require("../src/Controllers/FilesController").FilesController;
55

6-
var MockController = function(options) {
6+
const MockController = function(options) {
77
AdaptableController.call(this, options);
88
}
99
MockController.prototype = Object.create(AdaptableController.prototype);
1010
MockController.prototype.constructor = AdaptableController;
1111

1212
describe("AdaptableController", ()=>{
1313
it("should use the provided adapter", (done) => {
14-
var adapter = new FilesAdapter();
15-
var controller = new FilesController(adapter);
14+
const adapter = new FilesAdapter();
15+
const controller = new FilesController(adapter);
1616
expect(controller.adapter).toBe(adapter);
1717
// make sure _adapter is private
1818
expect(controller._adapter).toBe(undefined);
@@ -23,7 +23,7 @@ describe("AdaptableController", ()=>{
2323
});
2424

2525
it("should throw when creating a new mock controller", (done) => {
26-
var adapter = new FilesAdapter();
26+
const adapter = new FilesAdapter();
2727
expect(() => {
2828
new MockController(adapter);
2929
}).toThrow();
@@ -32,9 +32,9 @@ describe("AdaptableController", ()=>{
3232

3333
it("should fail setting the wrong adapter to the controller", (done) => {
3434
function WrongAdapter() {}
35-
var adapter = new FilesAdapter();
36-
var controller = new FilesController(adapter);
37-
var otherAdapter = new WrongAdapter();
35+
const adapter = new FilesAdapter();
36+
const controller = new FilesController(adapter);
37+
const otherAdapter = new WrongAdapter();
3838
expect(() => {
3939
controller.adapter = otherAdapter;
4040
}).toThrow();
@@ -43,7 +43,7 @@ describe("AdaptableController", ()=>{
4343

4444
it("should fail to instantiate a controller with wrong adapter", (done) => {
4545
function WrongAdapter() {}
46-
var adapter = new WrongAdapter();
46+
const adapter = new WrongAdapter();
4747
expect(() => {
4848
new FilesController(adapter);
4949
}).toThrow();
@@ -58,7 +58,7 @@ describe("AdaptableController", ()=>{
5858
});
5959

6060
it("should accept an object adapter", (done) => {
61-
var adapter = {
61+
const adapter = {
6262
createFile: function() { },
6363
deleteFile: function() { },
6464
getFileData: function() { },
@@ -77,7 +77,7 @@ describe("AdaptableController", ()=>{
7777
AGoodAdapter.prototype.getFileData = function() { };
7878
AGoodAdapter.prototype.getFileLocation = function() { };
7979

80-
var adapter = new AGoodAdapter();
80+
const adapter = new AGoodAdapter();
8181
expect(() => {
8282
new FilesController(adapter);
8383
}).not.toThrow();

spec/AdapterLoader.spec.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11

2-
var loadAdapter = require("../src/Adapters/AdapterLoader").loadAdapter;
3-
var FilesAdapter = require("@parse/fs-files-adapter").default;
4-
var S3Adapter = require("@parse/s3-files-adapter").default;
5-
var ParsePushAdapter = require("@parse/push-adapter").default;
2+
const loadAdapter = require("../src/Adapters/AdapterLoader").loadAdapter;
3+
const FilesAdapter = require("@parse/fs-files-adapter").default;
4+
const S3Adapter = require("@parse/s3-files-adapter").default;
5+
const ParsePushAdapter = require("@parse/push-adapter").default;
66
const Config = require('../src/Config');
77

88
describe("AdapterLoader", ()=>{
99

1010
it("should instantiate an adapter from string in object", (done) => {
11-
var adapterPath = require('path').resolve("./spec/MockAdapter");
11+
const adapterPath = require('path').resolve("./spec/MockAdapter");
1212

13-
var adapter = loadAdapter({
13+
const adapter = loadAdapter({
1414
adapter: adapterPath,
1515
options: {
1616
key: "value",
@@ -25,16 +25,16 @@ describe("AdapterLoader", ()=>{
2525
});
2626

2727
it("should instantiate an adapter from string", (done) => {
28-
var adapterPath = require('path').resolve("./spec/MockAdapter");
29-
var adapter = loadAdapter(adapterPath);
28+
const adapterPath = require('path').resolve("./spec/MockAdapter");
29+
const adapter = loadAdapter(adapterPath);
3030

3131
expect(adapter instanceof Object).toBe(true);
3232
done();
3333
});
3434

3535
it("should instantiate an adapter from string that is module", (done) => {
36-
var adapterPath = require('path').resolve("./src/Adapters/Files/FilesAdapter");
37-
var adapter = loadAdapter({
36+
const adapterPath = require('path').resolve("./src/Adapters/Files/FilesAdapter");
37+
const adapter = loadAdapter({
3838
adapter: adapterPath
3939
});
4040

@@ -47,7 +47,7 @@ describe("AdapterLoader", ()=>{
4747
});
4848

4949
it("should instantiate an adapter from npm module", (done) => {
50-
var adapter = loadAdapter({
50+
const adapter = loadAdapter({
5151
module: '@parse/fs-files-adapter'
5252
});
5353

@@ -60,69 +60,69 @@ describe("AdapterLoader", ()=>{
6060
});
6161

6262
it("should instantiate an adapter from function/Class", (done) => {
63-
var adapter = loadAdapter({
63+
const adapter = loadAdapter({
6464
adapter: FilesAdapter
6565
});
6666
expect(adapter instanceof FilesAdapter).toBe(true);
6767
done();
6868
});
6969

7070
it("should instantiate the default adapter from Class", (done) => {
71-
var adapter = loadAdapter(null, FilesAdapter);
71+
const adapter = loadAdapter(null, FilesAdapter);
7272
expect(adapter instanceof FilesAdapter).toBe(true);
7373
done();
7474
});
7575

7676
it("should use the default adapter", (done) => {
77-
var defaultAdapter = new FilesAdapter();
78-
var adapter = loadAdapter(null, defaultAdapter);
77+
const defaultAdapter = new FilesAdapter();
78+
const adapter = loadAdapter(null, defaultAdapter);
7979
expect(adapter instanceof FilesAdapter).toBe(true);
8080
done();
8181
});
8282

8383
it("should use the provided adapter", (done) => {
84-
var originalAdapter = new FilesAdapter();
85-
var adapter = loadAdapter(originalAdapter);
84+
const originalAdapter = new FilesAdapter();
85+
const adapter = loadAdapter(originalAdapter);
8686
expect(adapter).toBe(originalAdapter);
8787
done();
8888
});
8989

9090
it("should fail loading an improperly configured adapter", (done) => {
91-
var Adapter = function(options) {
91+
const Adapter = function(options) {
9292
if (!options.foo) {
9393
throw "foo is required for that adapter";
9494
}
9595
}
96-
var adapterOptions = {
96+
const adapterOptions = {
9797
param: "key",
9898
doSomething: function() {}
9999
};
100100

101101
expect(() => {
102-
var adapter = loadAdapter(adapterOptions, Adapter);
102+
const adapter = loadAdapter(adapterOptions, Adapter);
103103
expect(adapter).toEqual(adapterOptions);
104104
}).not.toThrow("foo is required for that adapter");
105105
done();
106106
});
107107

108108
it("should load push adapter from options", (done) => {
109-
var options = {
109+
const options = {
110110
android: {
111111
senderId: 'yolo',
112112
apiKey: 'yolo'
113113
}
114114
}
115115
expect(() => {
116-
var adapter = loadAdapter(undefined, ParsePushAdapter, options);
116+
const adapter = loadAdapter(undefined, ParsePushAdapter, options);
117117
expect(adapter.constructor).toBe(ParsePushAdapter);
118118
expect(adapter).not.toBe(undefined);
119119
}).not.toThrow();
120120
done();
121121
});
122122

123123
it("should load custom push adapter from string (#3544)", (done) => {
124-
var adapterPath = require('path').resolve("./spec/MockPushAdapter");
125-
var options = {
124+
const adapterPath = require('path').resolve("./spec/MockPushAdapter");
125+
const options = {
126126
ios: {
127127
bundleId: 'bundle.id'
128128
}
@@ -145,9 +145,9 @@ describe("AdapterLoader", ()=>{
145145
});
146146

147147
it("should load S3Adapter from direct passing", (done) => {
148-
var s3Adapter = new S3Adapter("key", "secret", "bucket")
148+
const s3Adapter = new S3Adapter("key", "secret", "bucket")
149149
expect(() => {
150-
var adapter = loadAdapter(s3Adapter, FilesAdapter);
150+
const adapter = loadAdapter(s3Adapter, FilesAdapter);
151151
expect(adapter).toBe(s3Adapter);
152152
}).not.toThrow();
153153
done();

spec/Analytics.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('AnalyticsController', () => {
1616
})
1717
}).then(() => {
1818
expect(analyticsAdapter.trackEvent).toHaveBeenCalled();
19-
var lastCall = analyticsAdapter.trackEvent.calls.first();
19+
const lastCall = analyticsAdapter.trackEvent.calls.first();
2020
const args = lastCall.args;
2121
expect(args[0]).toEqual('MyEvent');
2222
expect(args[1]).toEqual({
@@ -44,7 +44,7 @@ describe('AnalyticsController', () => {
4444
})
4545
}).then(() => {
4646
expect(analyticsAdapter.appOpened).toHaveBeenCalled();
47-
var lastCall = analyticsAdapter.appOpened.calls.first();
47+
const lastCall = analyticsAdapter.appOpened.calls.first();
4848
const args = lastCall.args;
4949
expect(args[0]).toEqual({
5050
dimensions: {

0 commit comments

Comments
 (0)