Skip to content

Commit 693237b

Browse files
committed
Test classes can no longer use function this
1 parent 85167a7 commit 693237b

48 files changed

Lines changed: 507 additions & 355 deletions

Some content is hidden

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

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Additions
66

77
### Fixes
8+
- Test classes cannot use function `this`
89
- npm update (includes audit & outdated)
910
- Lint (on master)
1011

test/spec/api/bodyguard/compare-id-to-user.spec.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ import { getBodyguardKeys, compareIdToUser } from '../../../../src/bodyguard';
66
* pointyapi/bodyguard
77
*/
88
describe('[Bodyguard] compareIdToUser', () => {
9+
let user;
10+
let guardKeys;
11+
912
beforeAll(() => {
1013
// Create user
11-
this.user = new ExampleUser();
12-
this.user.id = 2;
14+
user = new ExampleUser();
15+
user.id = 2;
1316

1417
// Get bodyguard keys
15-
this.guardKeys = getBodyguardKeys(new ExampleUser());
18+
guardKeys = getBodyguardKeys(new ExampleUser());
1619
});
1720

1821
it('returns true if the user matches', () => {
19-
// Check if this.user has an id of 2
20-
const result = compareIdToUser('id', 2, this.user, this.guardKeys);
22+
// Check if user has an id of 2
23+
const result = compareIdToUser('id', 2, user, guardKeys);
2124

2225
expect(result).toBe(true);
2326
});
2427

2528
it('returns false if the user does not match', () => {
2629
// This user should not have an id of 3
27-
const result = compareIdToUser('id', 3, this.user, this.guardKeys);
30+
const result = compareIdToUser('id', 3, user, guardKeys);
2831

2932
expect(result).toBe(false);
3033
});

test/spec/api/database/base-db.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,30 @@ import { BaseDb } from '../../../../src/database';
55
* pointyapi/database
66
*/
77
describe('[BaseDb]', () => {
8+
let baseDb;
9+
let clog;
10+
let cerr;
11+
812
beforeAll(() => {
9-
this.baseDb = new BaseDb();
13+
baseDb = new BaseDb();
1014
});
1115

1216
beforeEach(() => {
13-
this.clog = console.log;
14-
this.cerr = console.error;
17+
clog = console.log;
18+
cerr = console.error;
1519
});
1620

1721
afterEach(() => {
18-
console.log = this.clog;
19-
console.error = this.cerr;
22+
console.log = clog;
23+
console.error = cerr;
2024
});
2125

2226
it('contains setEntities() & allows chaining', () => {
23-
expect(this.baseDb.setEntities([])).toEqual(this.baseDb);
27+
expect(baseDb.setEntities([])).toEqual(baseDb);
2428
});
2529

2630
it('contains connect() & returns a promise', () => {
27-
expect(this.baseDb.connect({})).toEqual(jasmine.any(Promise));
31+
expect(baseDb.connect({})).toEqual(jasmine.any(Promise));
2832
});
2933

3034
it('can log a message', () => {
@@ -34,7 +38,7 @@ describe('[BaseDb]', () => {
3438
result = true;
3539
};
3640

37-
this.baseDb.logger();
41+
baseDb.logger();
3842
expect(result).toBe(true);
3943
});
4044
});

test/spec/api/database/postgres.spec.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,31 @@ const ROOT_PATH = require('app-root-path').toString();
88
* pointyapi/database
99
*/
1010
describe('[Database: Postgres]', async () => {
11+
let db;
12+
let clog;
13+
1114
beforeAll(() => {
12-
this.db = new PointyPostgres();
13-
this.db.connectionName = 'testconn';
14-
this.db.errorHandler = (error) => fail(error);
15-
this.db.logger = () => {};
15+
db = new PointyPostgres();
16+
db.connectionName = 'testconn';
17+
db.errorHandler = (error) => fail(error);
18+
db.logger = () => {};
1619
});
1720

1821
beforeEach(() => {
19-
this.clog = console.log;
22+
clog = console.log;
2023
});
2124

2225
afterEach(() => {
23-
console.log = this.clog;
26+
console.log = clog;
2427
});
2528

2629
it('can set entities', () => {
27-
this.db.setEntities([ ExampleUser ]);
30+
db.setEntities([ ExampleUser ]);
2831
});
2932

3033
it('can connect', async () => {
3134
// Database
32-
await this.db.connect(ROOT_PATH).catch((error) => fail(error));
35+
await db.connect(ROOT_PATH).catch((error) => fail(error));
3336
});
3437

3538
it('can connect with json options', async () => {

test/spec/api/endpoints/delete-endpoint.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ const errorHandler = (error) => fail(JSON.stringify(error));
1414
* pointyapi/endpoints
1515
*/
1616
describe('[Endpoints] Delete', () => {
17+
let cwarn;
18+
1719
beforeEach(() => {
18-
this.cwarn = console.warn;
20+
cwarn = console.warn;
1921
console.warn = () => {};
2022
});
2123

2224
afterEach(() => {
23-
console.warn = this.cwarn;
25+
console.warn = cwarn;
2426
});
2527

2628
it('can delete', async () => {

test/spec/api/endpoints/get-endpoint.spec.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,34 @@ import { getRepository } from 'typeorm';
1212
* pointyapi/endpoints
1313
*/
1414
describe('[Endpoints] Get', () => {
15+
let cwarn;
16+
let user1;
17+
let user2;
18+
1519
beforeEach(() => {
16-
this.cwarn = console.warn;
20+
cwarn = console.warn;
1721
console.warn = () => {};
1822
});
1923

2024
afterEach(() => {
21-
console.warn = this.cwarn;
25+
console.warn = cwarn;
2226
});
2327

2428
beforeAll(() => {
2529
// Create users
26-
this.user1 = new ExampleUser();
27-
this.user1.fname = 'Get';
28-
this.user1.lname = 'Endpoint';
29-
this.user1.username = 'getEndpoint1';
30-
this.user1.password = 'password123';
31-
this.user1.email = 'get1@example.com';
32-
33-
this.user2 = new ExampleUser();
34-
this.user2.fname = 'Get';
35-
this.user2.lname = 'Endpoint';
36-
this.user2.username = 'getEndpoint2';
37-
this.user2.password = 'password123';
38-
this.user2.email = 'get2@example.com';
30+
user1 = new ExampleUser();
31+
user1.fname = 'Get';
32+
user1.lname = 'Endpoint';
33+
user1.username = 'getEndpoint1';
34+
user1.password = 'password123';
35+
user1.email = 'get1@example.com';
36+
37+
user2 = new ExampleUser();
38+
user2.fname = 'Get';
39+
user2.lname = 'Endpoint';
40+
user2.username = 'getEndpoint2';
41+
user2.password = 'password123';
42+
user2.email = 'get2@example.com';
3943
});
4044

4145
it('returns the payload', async () => {
@@ -49,7 +53,7 @@ describe('[Endpoints] Get', () => {
4953
}
5054

5155
// Set payload
52-
request.payload = [ this.user1, this.user2 ];
56+
request.payload = [ user1, user2 ];
5357

5458
// Check for getResponder()
5559
response.getResponder = (result) => {
@@ -75,7 +79,7 @@ describe('[Endpoints] Get', () => {
7579
}
7680

7781
// Set payload
78-
request.payload = [ this.user1, this.user2 ];
82+
request.payload = [ user1, user2 ];
7983

8084
// Check for getResponder()
8185
response.getResponder = (result) => {
@@ -99,7 +103,7 @@ describe('[Endpoints] Get', () => {
99103
}
100104

101105
// Set payload
102-
request.payload = this.user1;
106+
request.payload = user1;
103107

104108
// Check for getResponder()
105109
response.getResponder = (result) => {

test/spec/api/endpoints/login-endpoint.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import { addResource } from '../../../../src/utils';
1212
* pointyapi/endpoints
1313
*/
1414
describe('[Endpoints] Login', async () => {
15+
let cwarn;
16+
1517
beforeEach(() => {
16-
this.cwarn = console.warn;
18+
cwarn = console.warn;
1719
console.warn = () => {};
1820
});
1921

2022
afterEach(() => {
21-
console.warn = this.cwarn;
23+
console.warn = cwarn;
2224
});
2325

2426
beforeAll(async () => {

test/spec/api/endpoints/logout-endpoint.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import { addResource } from '../../../../src/utils';
1212
* pointyapi/endpoints
1313
*/
1414
describe('[Endpoints] Logout', async () => {
15+
let cwarn;
16+
1517
beforeEach(() => {
16-
this.cwarn = console.warn;
18+
cwarn = console.warn;
1719
console.warn = () => {};
1820
});
1921

2022
afterEach(() => {
21-
console.warn = this.cwarn;
23+
console.warn = cwarn;
2224
});
2325

2426
beforeAll(async () => {

test/spec/api/endpoints/patch-endpoint.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { getRepository } from 'typeorm';
1111
* pointyapi/endpoints
1212
*/
1313
describe('[Endpoints] Patch', () => {
14+
let cwarn;
15+
1416
beforeEach(() => {
15-
this.cwarn = console.warn;
17+
cwarn = console.warn;
1618
console.warn = () => {};
1719
});
1820

1921
afterEach(() => {
20-
console.warn = this.cwarn;
22+
console.warn = cwarn;
2123
});
2224

2325
it('can patch', async () => {

test/spec/api/endpoints/post-endpoint.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ import { getRepository } from 'typeorm';
1111
* pointyapi/endpoints
1212
*/
1313
describe('[Endpoints] Post', () => {
14+
let cwarn;
15+
1416
beforeEach(() => {
15-
this.cwarn = console.warn;
17+
cwarn = console.warn;
1618
console.warn = () => {};
1719
});
1820

1921
afterEach(() => {
20-
console.warn = this.cwarn;
22+
console.warn = cwarn;
2123
});
2224

2325
it('can post (single)', async () => {

0 commit comments

Comments
 (0)