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

Commit d657791

Browse files
committed
test(unit): Fix unit tests (#78)
1 parent 6634469 commit d657791

6 files changed

Lines changed: 55 additions & 13 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"express": "4.17.1"
4040
},
4141
"devDependencies": {
42-
"@mocks-server/core": "1.5.1",
42+
"@mocks-server/core": "1.5.3",
4343
"eslint": "7.12.1",
4444
"eslint-config-prettier": "6.15.0",
4545
"eslint-plugin-prettier": "3.1.4",

src/Alerts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
Copyright 2020 Javier Brea
3+
Copyright 2019 XbyOrange
34
45
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
56

test/unit/Core.mocks.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ class CoreMock {
4646
addRouter: this._sandbox.stub(),
4747
removeRouter: this._sandbox.stub(),
4848
behaviors: {
49-
currentFromCollection: "foo-current",
49+
count: 0,
5050
collection: "foo-behaviors-collection",
51+
ids: [],
52+
current: {},
53+
currentId: "foo",
5154
},
55+
alerts: [],
5256
serverError: null,
5357
_eventEmitter: {
5458
on: this._sandbox.stub(),

test/unit/src/Alerts.mocks.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Copyright 2020 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/Alerts");
15+
16+
const Alerts = require("../../../src/Alerts");
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+
Alerts.mockImplementation(() => this._stubs);
27+
}
28+
29+
get stubs() {
30+
return {
31+
Constructor: Alerts,
32+
instance: this._stubs,
33+
};
34+
}
35+
36+
restore() {
37+
this._sandbox.restore();
38+
}
39+
};
40+
41+
module.exports = Mock;

test/unit/src/Plugin.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const CoreMocks = require("../Core.mocks");
1717
const DeprecatedApiMocks = require("./deprecated/Api.mocks");
1818
const SettingsMocks = require("./Settings.mocks");
1919
const BehaviorsMocks = require("./Behaviors.mocks");
20+
const AlertsMocks = require("./Alerts.mocks");
2021
const FixturesMock = require("./Fixtures.mocks");
2122
const AboutMock = require("./About.mocks");
2223

@@ -27,6 +28,7 @@ describe("Plugin", () => {
2728
let libMocks;
2829
let settingsMocks;
2930
let behaviorsMocks;
31+
let alertsMocks;
3032
let fixturesMock;
3133
let deprecatedApiMock;
3234
let deprecatedApiInstance;
@@ -40,6 +42,7 @@ describe("Plugin", () => {
4042
libMocks = new LibMocks();
4143
settingsMocks = new SettingsMocks();
4244
behaviorsMocks = new BehaviorsMocks();
45+
alertsMocks = new AlertsMocks();
4346
aboutMock = new AboutMock();
4447
fixturesMock = new FixturesMock();
4548
deprecatedApiMock = new DeprecatedApiMocks();
@@ -55,6 +58,7 @@ describe("Plugin", () => {
5558
libMocks.restore();
5659
settingsMocks.restore();
5760
behaviorsMocks.restore();
61+
alertsMocks.restore();
5862
fixturesMock.restore();
5963
coreMock.restore();
6064
aboutMock.restore();

0 commit comments

Comments
 (0)