Skip to content

Commit 0f1121e

Browse files
committed
docs(README): stable release for angular 13
1 parent 79632d2 commit 0f1121e

38 files changed

+230
-199
lines changed

README.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,17 @@
1414

1515
The current version of the library **has been tested** and **can be used** with:
1616

17-
| Angular | ng-mocks | Jasmine | Jest | Ivy |
18-
| -------: | :-----------------------------------------------------------: | :-----: | :--: | :-: |
19-
| >13.0.2 | [in progress](https://github.com/ike18t/ng-mocks/issues/1427) | | | |
20-
| <=13.0.2 | latest | yes | yes | yes |
21-
| 12 | latest | yes | yes | yes |
22-
| 11 | latest | yes | yes | yes |
23-
| 10 | latest | yes | yes | yes |
24-
| 9 | latest | yes | yes | yes |
25-
| 8 | latest | yes | yes | |
26-
| 7 | latest | yes | yes | |
27-
| 6 | latest | yes | yes | |
28-
| 5 | latest | yes | yes | |
29-
30-
**PLEASE NOTE: If you are using Angular 13 or planning to use it,
31-
please note that currently only Angular `<=13.0.2` is supported,
32-
[work is in progress](https://github.com/ike18t/ng-mocks/issues/1427) to implement support of Angular `>13.0.2`.
33-
Thank you for patience, understanding and support.**
34-
35-
To stay with the latest supported version, you can set the versions to `<=13.0.2` in your `package.json` for `@angular/*` and `@angular-devkit/*`.
17+
| Angular | ng-mocks | Jasmine | Jest | Ivy |
18+
| ------: | :------: | :-----: | :--: | :-: |
19+
| 13 | latest | yes | yes | yes |
20+
| 12 | latest | yes | yes | yes |
21+
| 11 | latest | yes | yes | yes |
22+
| 10 | latest | yes | yes | yes |
23+
| 9 | latest | yes | yes | yes |
24+
| 8 | latest | yes | yes | |
25+
| 7 | latest | yes | yes | |
26+
| 6 | latest | yes | yes | |
27+
| 5 | latest | yes | yes | |
3628

3729
## Important links
3830

@@ -77,7 +69,7 @@ An example of a spec for a profile edit component.
7769
// lastName, and a user can edit them.
7870
// In the following test suite, we would like to
7971
// cover behavior of the component.
80-
describe('profile', () => {
72+
describe('profile:classic', () => {
8173
// First of all, we would like to reuse the same
8274
// TestBed in every test.
8375
// ngMocks.faster suppresses reset of TestBed
@@ -86,11 +78,14 @@ describe('profile', () => {
8678
// https://ng-mocks.sudo.eu/api/ngMocks/faster
8779
ngMocks.faster();
8880

81+
// Helps to reset customizations after each test.
82+
MockInstance.scope();
83+
8984
// Let's declare TestBed in beforeAll
9085
// instead of beforeEach.
9186
// The code mocks everything in SharedModule
9287
// and provides a mock AuthService.
93-
beforeAll(() => {
88+
beforeAll(async () => {
9489
return TestBed.configureTestingModule({
9590
imports: [
9691
MockModule(SharedModule), // mock
@@ -141,7 +136,7 @@ describe('profile', () => {
141136
const spySave = MockInstance(
142137
StorageService,
143138
'save',
144-
jasmine.createSpy('StorageService.save'),
139+
jasmine.createSpy(), // or jest.fn()
145140
);
146141

147142
// Renders <profile [profile]="params.profile">

docs/articles/api/MockComponent.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Please, pay attention to comments in the code.
102102
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockComponent/test.spec.ts&initialpath=%3Fspec%3DMockComponent)
103103
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockComponent/test.spec.ts&initialpath=%3Fspec%3DMockComponent)
104104

105-
```ts
105+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockComponent/test.spec.ts"
106106
describe('MockComponent', () => {
107107
beforeEach(() => {
108108
return MockBuilder(TestedComponent).mock(DependencyComponent);
@@ -147,7 +147,11 @@ describe('MockComponent', () => {
147147
// called 'someOutput'. TestedComponent listens on the output via
148148
// `(someOutput)="trigger($event)"`.
149149
// Let's install a spy and trigger the output.
150-
spyOn(component, 'trigger');
150+
ngMocks.stubMember(
151+
component,
152+
'trigger',
153+
jasmine.createSpy(), // or jest.fn()
154+
);
151155
mockComponent.someOutput.emit({
152156
payload: 'foo',
153157
});
@@ -189,7 +193,10 @@ describe('MockComponent', () => {
189193
// componentInstance is a MockedComponent<T> to access
190194
// its `__render` method. `isMockOf` function helps here.
191195
const mockComponent = fixture.point.componentInstance;
192-
ngMocks.render(mockComponent, ngMocks.findTemplateRef('something'));
196+
ngMocks.render(
197+
mockComponent,
198+
ngMocks.findTemplateRef('something'),
199+
);
193200

194201
// The rendered template is wrapped by <div data-key="something">.
195202
// We can use this selector to assert exactly its content.

docs/articles/api/MockDirective.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Please, pay attention to comments in the code.
102102
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockDirective-Attribute/test.spec.ts&initialpath=%3Fspec%3DMockDirective%3AAttribute)
103103
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockDirective-Attribute/test.spec.ts&initialpath=%3Fspec%3DMockDirective%3AAttribute)
104104

105-
```ts
105+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockDirective-Attribute/test.spec.ts"
106106
describe('MockDirective:Attribute', () => {
107107
beforeEach(() => {
108108
return MockBuilder(TestedComponent).mock(DependencyDirective);
@@ -151,7 +151,11 @@ describe('MockDirective:Attribute', () => {
151151
// 'someOutput'. TestedComponent listens on the output via
152152
// `(someOutput)="trigger($event)"`.
153153
// Let's install a spy and trigger the output.
154-
spyOn(component, 'trigger');
154+
ngMocks.stubMember(
155+
component,
156+
'trigger',
157+
jasmine.createSpy(), // or jest.fn()
158+
);
155159
mockDirective.someOutput.emit();
156160

157161
// Assert on the effect.
@@ -173,7 +177,7 @@ if we want to assert on its nested elements.
173177
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockDirective-Structural/test.spec.ts&initialpath=%3Fspec%3DMockDirective%3AStructural)
174178
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockDirective-Structural/test.spec.ts&initialpath=%3Fspec%3DMockDirective%3AStructural)
175179

176-
```ts
180+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockDirective-Structural/test.spec.ts"
177181
describe('MockDirective:Structural', () => {
178182
// IMPORTANT: by default structural directives are not rendered.
179183
// Because they might require a context which should be provided.

docs/articles/api/MockInstance.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,8 @@ Please, pay attention to comments in the code.
248248
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockInstance/test.spec.ts&initialpath=%3Fspec%3DMockInstance)
249249
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockInstance/test.spec.ts&initialpath=%3Fspec%3DMockInstance)
250250

251-
```ts
251+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockInstance/test.spec.ts"
252252
describe('MockInstance', () => {
253-
MockInstance.scope();
254-
255253
// A normal setup of the TestBed, TargetComponent will be replaced
256254
// with its mock object.
257255
// Do not forget to return the promise of MockBuilder.
@@ -268,6 +266,11 @@ describe('MockInstance', () => {
268266
}));
269267
});
270268

269+
afterEach(() => {
270+
// Resets customizations
271+
MockInstance(ChildComponent);
272+
});
273+
271274
it('should render', () => {
272275
// Without the custom initialization rendering would fail here
273276
// with "Cannot read property 'subscribe' of undefined".

docs/articles/api/MockModule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Please, pay attention to comments in the code.
104104
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockModule/test.spec.ts&initialpath=%3Fspec%3DMockModule)
105105
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockModule/test.spec.ts&initialpath=%3Fspec%3DMockModule)
106106

107-
```ts
107+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockModule/test.spec.ts"
108108
describe('MockModule', () => {
109109
beforeEach(() => {
110110
return MockBuilder(TestedComponent).mock(DependencyModule);

docs/articles/api/MockPipe.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,14 @@ Please, pay attention to comments in the code.
103103
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockPipe/test.spec.ts&initialpath=%3Fspec%3DMockPipe)
104104
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockPipe/test.spec.ts&initialpath=%3Fspec%3DMockPipe)
105105

106-
```ts
106+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockPipe/test.spec.ts"
107107
describe('MockPipe', () => {
108108
// A fake transform function.
109109
const fakeTransform = (...args: string[]) => JSON.stringify(args);
110110

111111
// A spy, just in case if we want to verify
112112
// how the pipe has been called.
113-
const spy = jasmine.createSpy('transform')
114-
.and.callFake(fakeTransform);
113+
const spy = jasmine.createSpy().and.callFake(fakeTransform);
115114
// in case of jest
116115
// const spy = jest.fn().mockImplementation(fakeTransform);
117116

@@ -122,8 +121,9 @@ describe('MockPipe', () => {
122121
it('transforms values to json', () => {
123122
const fixture = MockRender(TestedComponent);
124123

125-
expect(fixture.nativeElement.innerHTML)
126-
.toEqual('<component>["foo"]</component>');
124+
expect(fixture.nativeElement.innerHTML).toEqual(
125+
'<component>["foo"]</component>',
126+
);
127127

128128
// Also we can find an instance of the pipe in
129129
// the fixture if it is needed.

docs/articles/api/MockProvider.md

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Please, pay attention to comments in the code.
109109
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockProvider/test.spec.ts&initialpath=%3Fspec%3DMockProvider)
110110
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockProvider/test.spec.ts&initialpath=%3Fspec%3DMockProvider)
111111

112-
```ts
112+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockProvider/test.spec.ts"
113113
describe('MockProvider', () => {
114114
const mockObj = { value: 123 };
115115

@@ -132,26 +132,21 @@ describe('MockProvider', () => {
132132
// overriding the token's data that does affect the provided token.
133133
mockObj.value = 321;
134134
const fixture = MockRender(TargetComponent);
135-
const injector = fixture.point.injector;
136-
137-
expect(injector.get(Dependency1Service).echo())
138-
.toBeUndefined();
139-
expect(injector.get(Dependency2Service).echo())
140-
.toBeUndefined();
141-
expect(injector.get(OBJ_TOKEN))
142-
.toBe(mockObj);
143-
expect(fixture.nativeElement.innerHTML)
144-
.not.toContain('"target"');
145-
expect(fixture.nativeElement.innerHTML)
146-
.toContain('"d2:mock"');
147-
expect(fixture.nativeElement.innerHTML)
148-
.toContain('"mock token"');
149-
expect(fixture.nativeElement.innerHTML)
150-
.toContain('"mock"');
151-
expect(fixture.nativeElement.innerHTML)
152-
.toContain('"value": 321');
153-
expect(fixture.nativeElement.innerHTML)
154-
.toContain('"pri"');
135+
expect(
136+
fixture.point.injector.get(Dependency1Service).echo(),
137+
).toBeUndefined();
138+
expect(
139+
fixture.point.injector.get(Dependency2Service).echo(),
140+
).toBeUndefined();
141+
expect(fixture.point.injector.get(OBJ_TOKEN)).toBe(
142+
mockObj as any,
143+
);
144+
expect(fixture.nativeElement.innerHTML).not.toContain('"target"');
145+
expect(fixture.nativeElement.innerHTML).toContain('"d2:mock"');
146+
expect(fixture.nativeElement.innerHTML).toContain('"mock token"');
147+
expect(fixture.nativeElement.innerHTML).toContain('"mock"');
148+
expect(fixture.nativeElement.innerHTML).toContain('"value": 321');
149+
expect(fixture.nativeElement.innerHTML).toContain('"pri"');
155150
});
156151
});
157152
```

docs/articles/api/MockRender.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ Please, pay attention to comments in the code.
483483
- [Try it on StackBlitz](https://stackblitz.com/github/ng-mocks/examples?file=src/examples/MockRender/test.spec.ts&initialpath=%3Fspec%3DMockRender)
484484
- [Try it on CodeSandbox](https://codesandbox.io/s/github/ng-mocks/examples?file=/src/examples/MockRender/test.spec.ts&initialpath=%3Fspec%3DMockRender)
485485

486-
```ts
486+
```ts title="https://github.com/ike18t/ng-mocks/blob/master/examples/MockRender/test.spec.ts"
487487
describe('MockRender', () => {
488488
// Do not forget to return the promise of MockBuilder.
489489
beforeEach(() => MockBuilder(TestedComponent, DependencyModule));
@@ -514,10 +514,10 @@ describe('MockRender', () => {
514514

515515
// ngMocks.input helps to get the current value of an input on
516516
// a related debugElement without knowing its owner.
517-
expect(ngMocks.input(fixture.point, 'value1'))
518-
.toEqual('something1');
519-
expect(ngMocks.input(fixture.point, 'value2'))
520-
.toEqual('check');
517+
expect(ngMocks.input(fixture.point, 'value1')).toEqual(
518+
'something1',
519+
);
520+
expect(ngMocks.input(fixture.point, 'value2')).toEqual('check');
521521

522522
// ngMocks.output does the same with outputs.
523523
ngMocks.output(fixture.point, 'trigger').emit('foo1');
@@ -538,10 +538,12 @@ describe('MockRender', () => {
538538
});
539539

540540
// Checking the inputs.
541-
expect(ngMocks.input(fixture.point, 'value1'))
542-
.toEqual('something2');
543-
expect(ngMocks.input(fixture.point, 'value2'))
544-
.toBeUndefined();
541+
expect(ngMocks.input(fixture.point, 'value1')).toEqual(
542+
'something2',
543+
);
544+
expect(ngMocks.input(fixture.point, 'value2')).toEqual(
545+
'default2',
546+
);
545547

546548
// Checking the outputs.
547549
ngMocks.output(fixture.point, 'trigger').emit('foo2');
@@ -551,8 +553,7 @@ describe('MockRender', () => {
551553
// the testing component.
552554
fixture.componentInstance.value1 = 'updated';
553555
fixture.detectChanges();
554-
expect(ngMocks.input(fixture.point, 'value1'))
555-
.toEqual('updated');
556+
expect(ngMocks.input(fixture.point, 'value1')).toEqual('updated');
556557
});
557558
});
558559
```

docs/articles/api/ngMocks/click.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ngMocks.click('[data-role="link"]');
3939
ngMocks.click(['data-role']);
4040
```
4141
```ts
42-
ngMocks.click(['data-role', 'linke']);
42+
ngMocks.click(['data-role', 'link']);
4343
```
4444

4545
Under the hood `ngMocks.click` uses [`ngMocks.trigger`](./trigger.md),

docs/articles/api/ngMocks/defaultMock.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ declare class MyComponent {
2323
}
2424
```
2525

26-
```ts
27-
// src/test.ts
28-
26+
```ts title="src/test.ts"
2927
// the returned object will be applied to the component instance.
3028
ngMocks.defaultMock(MyComponent, () => ({
3129
stream$: EMPTY,

0 commit comments

Comments
 (0)