ng-mocks 14.3.1 → 14.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -21
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -1
- package/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
[<img src="https://img.shields.io/npm/v/ng-mocks" alt="npm version" width="88" height="20" />](https://www.npmjs.com/package/ng-mocks)
|
|
3
3
|
[<img src="https://img.shields.io/circleci/build/github/help-me-mom/ng-mocks/master" alt="build status" width="88" height="20" />](https://app.circleci.com/pipelines/github/help-me-mom/ng-mocks?branch=master)
|
|
4
4
|
[<img src="https://img.shields.io/coveralls/github/help-me-mom/ng-mocks/master" alt="coverage status" width="104" height="20" />](https://coveralls.io/github/help-me-mom/ng-mocks?branch=master)
|
|
5
|
-
[<img src="https://img.shields.io/lgtm/grade/javascript/g/help-me-mom/ng-mocks" alt="language grade" width="138" height="20" />](https://lgtm.com/projects/g/help-me-mom/ng-mocks/context:javascript)
|
|
6
5
|
|
|
7
6
|
# Mock components, services and more out of annoying dependencies for simplification of Angular testing
|
|
8
7
|
|
|
@@ -71,28 +70,36 @@ An example of a spec for a profile edit component.
|
|
|
71
70
|
// lastName, and a user can edit them.
|
|
72
71
|
// In the following test suite, we would like to
|
|
73
72
|
// cover behavior of the component.
|
|
74
|
-
describe('profile:
|
|
73
|
+
describe('profile:builder', () => {
|
|
75
74
|
// Helps to reset customizations after each test.
|
|
76
75
|
MockInstance.scope();
|
|
77
76
|
|
|
78
|
-
// Let's
|
|
79
|
-
//
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
77
|
+
// Let's configure TestBed via MockBuilder.
|
|
78
|
+
// The code below says to mock everything in
|
|
79
|
+
// ProfileModule except ProfileComponent and
|
|
80
|
+
// ReactiveFormsModule.
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
// The result of MockBuilder should be returned.
|
|
83
|
+
// https://ng-mocks.sudo.eu/api/MockBuilder
|
|
84
|
+
return MockBuilder(
|
|
85
|
+
ProfileComponent,
|
|
86
|
+
ProfileModule,
|
|
87
|
+
).keep(ReactiveFormsModule);
|
|
88
|
+
// // or old fashion way
|
|
89
|
+
// return TestBed.configureTestingModule({
|
|
90
|
+
// imports: [
|
|
91
|
+
// MockModule(SharedModule), // mock
|
|
92
|
+
// ReactiveFormsModule, // real
|
|
93
|
+
// ],
|
|
94
|
+
// declarations: [
|
|
95
|
+
// ProfileComponent, // real
|
|
96
|
+
// MockPipe(CurrencyPipe), // mock
|
|
97
|
+
// MockDirective(HoverDirective), // mock
|
|
98
|
+
// ],
|
|
99
|
+
// providers: [
|
|
100
|
+
// MockProvider(AuthService), // mock
|
|
101
|
+
// ],
|
|
102
|
+
// }).compileComponents();
|
|
96
103
|
});
|
|
97
104
|
|
|
98
105
|
// A test to ensure that ProfileComponent
|
|
@@ -104,12 +111,14 @@ describe('profile:classic', () => {
|
|
|
104
111
|
// onPush change detection, and creates a
|
|
105
112
|
// wrapper component with a template like
|
|
106
113
|
// <app-root ...allInputs></profile>
|
|
114
|
+
// and renders it.
|
|
115
|
+
// It also respects all lifecycle hooks.
|
|
107
116
|
// https://ng-mocks.sudo.eu/api/MockRender
|
|
108
117
|
const fixture = MockRender(ProfileComponent);
|
|
109
118
|
|
|
110
119
|
expect(
|
|
111
120
|
fixture.point.componentInstance,
|
|
112
|
-
).toEqual(
|
|
121
|
+
).toEqual(assertion.any(ProfileComponent));
|
|
113
122
|
});
|
|
114
123
|
|
|
115
124
|
// A test to ensure that the component listens
|