Skip to content
This repository was archived by the owner on Mar 28, 2022. It is now read-only.

Commit 8acb6c2

Browse files
committed
Fix unit tests
1 parent a1002f5 commit 8acb6c2

10 files changed

Lines changed: 254 additions & 96 deletions

File tree

jest.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ module.exports = {
2626

2727
// The glob patterns Jest uses to detect test files
2828
testMatch: ["**/test/unit/**/?(*.)+(spec|test).js?(x)"],
29-
//testMatch: ["**/test/unit/core/Plugins.spec.js"],
3029

3130
// The test environment that will be used for testing
3231
testEnvironment: "node"

package-lock.json

Lines changed: 41 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
"@mocks-server/core": "^1.1.0"
3636
},
3737
"dependencies": {
38+
"@hapi/boom": "8.0.1",
3839
"express": "4.17.1"
3940
},
4041
"devDependencies": {
41-
"@mocks-server/core": "^1.1.0",
42+
"@mocks-server/core": "^1.2.0",
4243
"coveralls": "^3.0.7",
4344
"eslint": "6.6.0",
4445
"eslint-config-prettier": "6.5.0",

test/unit/Core.mocks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class CoreMock {
4343
addCustomSetting: this._sandbox.stub(),
4444
addSetting: this._sandbox.stub(),
4545
addRouter: this._sandbox.stub(),
46+
removeRouter: this._sandbox.stub(),
4647
behaviors: {
4748
currentFromCollection: "foo-current",
4849
collection: "foo-behaviors-collection"

test/unit/Libs.mocks.js

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,21 @@ Unless required by applicable law or agreed to in writing, software distributed
1111

1212
const sinon = require("sinon");
1313

14-
const http = require("http");
15-
16-
jest.mock("express");
17-
1814
const express = require("express");
1915

20-
class CallBackRunner {
21-
constructor() {
22-
this.runner = this.runner.bind(this);
23-
}
24-
25-
runner(eventName, cb) {
26-
if (this._returns !== undefined) {
27-
cb(this._returns);
28-
}
29-
}
30-
31-
returns(code) {
32-
this._returns = code;
33-
}
34-
}
35-
3616
class Mock {
3717
constructor() {
3818
this._sandbox = sinon.createSandbox();
3919

40-
const httpCreateServerOnError = new CallBackRunner();
41-
const httpCreateServerOnListen = new CallBackRunner();
42-
4320
this._stubs = {
4421
express: {
4522
use: this._sandbox.stub(),
46-
options: this._sandbox.stub()
47-
},
48-
http: {
49-
createServer: {
50-
on: this._sandbox.stub().callsFake(httpCreateServerOnError.runner),
51-
onError: httpCreateServerOnError,
52-
listen: this._sandbox.stub().callsFake(httpCreateServerOnListen.runner),
53-
onListen: httpCreateServerOnListen,
54-
close: this._sandbox.stub().callsFake(cb => cb())
55-
}
23+
patch: this._sandbox.stub(),
24+
get: this._sandbox.stub()
5625
}
5726
};
5827

59-
express.mockImplementation(() => this._stubs.express);
60-
this._sandbox.stub(http, "createServer").returns(this._stubs.http.createServer);
28+
this._sandbox.stub(express, "Router").returns(this._stubs.express);
6129
}
6230

6331
get stubs() {

test/unit/src/Behaviors.mocks.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2019 Javier Brea
3+
Copyright 2019 XbyOrange
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10+
*/
11+
12+
const sinon = require("sinon");
13+
14+
jest.mock("../../../src/Behaviors");
15+
16+
const Behaviors = require("../../../src/Behaviors");
17+
18+
const Mock = class Mock {
19+
constructor() {
20+
this._sandbox = sinon.createSandbox();
21+
22+
this._stubs = {
23+
init: this._sandbox.stub()
24+
};
25+
26+
Behaviors.mockImplementation(() => this._stubs);
27+
}
28+
29+
get stubs() {
30+
return {
31+
Constructor: Behaviors,
32+
instance: this._stubs
33+
};
34+
}
35+
36+
restore() {
37+
this._sandbox.restore();
38+
}
39+
};
40+
41+
module.exports = Mock;

test/unit/src/Fixtures.mocks.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2019 Javier Brea
3+
Copyright 2019 XbyOrange
4+
5+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10+
*/
11+
12+
const sinon = require("sinon");
13+
14+
jest.mock("../../../src/Fixtures");
15+
16+
const Fixtures = require("../../../src/Fixtures");
17+
18+
const Mock = class Mock {
19+
constructor() {
20+
this._sandbox = sinon.createSandbox();
21+
22+
this._stubs = {
23+
init: this._sandbox.stub()
24+
};
25+
26+
Fixtures.mockImplementation(() => this._stubs);
27+
}
28+
29+
get stubs() {
30+
return {
31+
Constructor: Fixtures,
32+
instance: this._stubs
33+
};
34+
}
35+
36+
restore() {
37+
this._sandbox.restore();
38+
}
39+
};
40+
41+
module.exports = Mock;

0 commit comments

Comments
 (0)