ng-mocks 14.15.0 → 14.15.2

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 CHANGED
@@ -1,25 +1,27 @@
1
1
  [<img src="https://img.shields.io/gitter/room/help-me-mom/ng-mocks" alt="chat on gitter" width="90" height="20" />](https://gitter.im/ng-mocks/community)
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
- [<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
- [<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)
3
+ [<img src="https://img.shields.io/circleci/build/github/help-me-mom/ng-mocks/main" alt="build status" width="88" height="20" />](https://app.circleci.com/pipelines/github/help-me-mom/ng-mocks?branch=main)
4
+ [<img src="https://img.shields.io/codecov/c/github/help-me-mom/ng-mocks/main" alt="coverage status" width="104" height="20" />](https://codecov.io/gh/help-me-mom/ng-mocks)
5
5
 
6
- # Mock components, services and more out of annoying dependencies for simplification of Angular testing
6
+ # Mock components, services, and more to simplify Angular testing
7
7
 
8
- `ng-mocks` facilitates **Angular testing** and helps to:
8
+ `ng-mocks` simplifies **Angular testing** and helps you:
9
9
 
10
10
  - **mock Components**, Directives, Pipes, Modules, Services and Tokens
11
11
  - reduce boilerplate in tests
12
- - access declarations via simple interface
12
+ - access declarations through a simple interface
13
13
 
14
14
  The current version of the library **has been tested** and **can be used** with:
15
15
 
16
16
  | angular | ng-mocks | jasmine | jest | ivy | standalone | signals | defer |
17
17
  | ------: | :------: | :-----: | :--: | :-: | :--------: | :-----: | :---: |
18
- | 20 | latest | yes | yes | yes | yes | no | no |
19
- | 19 | latest | yes | yes | yes | yes | no | no |
20
- | 18 | latest | yes | yes | yes | yes | no | no |
21
- | 17 | latest | yes | yes | yes | yes | no | no |
22
- | 16 | latest | yes | yes | yes | yes | no | |
18
+ | 22 | latest | yes | yes | yes | yes | yes | no |
19
+ | 21 | latest | yes | yes | yes | yes | yes | no |
20
+ | 20 | latest | yes | yes | yes | yes | yes | no |
21
+ | 19 | latest | yes | yes | yes | yes | yes | no |
22
+ | 18 | latest | yes | yes | yes | yes | yes | no |
23
+ | 17 | latest | yes | yes | yes | yes | yes | no |
24
+ | 16 | latest | yes | yes | yes | yes | yes | |
23
25
  | 15 | latest | yes | yes | yes | yes | | |
24
26
  | 14 | latest | yes | yes | yes | yes | | |
25
27
  | 13 | latest | yes | yes | yes | | | |
@@ -35,7 +37,7 @@ The current version of the library **has been tested** and **can be used** with:
35
37
  ## Important links
36
38
 
37
39
  - **[Documentation with examples of Angular testing](https://ng-mocks.sudo.eu)**
38
- - [CHANGELOG](https://github.com/help-me-mom/ng-mocks/blob/master/CHANGELOG.md)
40
+ - [CHANGELOG](https://github.com/help-me-mom/ng-mocks/blob/main/CHANGELOG.md)
39
41
  - [GitHub repo](https://github.com/help-me-mom/ng-mocks)
40
42
  - [NPM package](https://www.npmjs.com/package/ng-mocks)
41
43
 
@@ -49,8 +51,8 @@ The current version of the library **has been tested** and **can be used** with:
49
51
 
50
52
  ## Very short introduction
51
53
 
52
- Global configuration for mocks in `src/test.ts`.
53
- In case of jest, `src/setup-jest.ts` / `src/test-setup.ts` should be used.
54
+ Put the global configuration for mocks in `src/test.ts`.
55
+ For Jest, use `src/setup-jest.ts` / `src/test-setup.ts`.
54
56
 
55
57
  ```ts title="src/test.ts"
56
58
  // All methods in mock declarations and providers
@@ -75,7 +77,7 @@ An example of a spec for a profile edit component.
75
77
  // and it has 3 text fields: email, firstName,
76
78
  // lastName, and a user can edit them.
77
79
  // In the following test suite, we would like to
78
- // cover behavior of the component.
80
+ // cover the behavior of the component.
79
81
  describe('profile:builder', () => {
80
82
  // Helps to reset customizations after each test.
81
83
  // Alternatively, you can enable
@@ -93,7 +95,7 @@ describe('profile:builder', () => {
93
95
  ProfileComponent,
94
96
  ProfileModule,
95
97
  ).keep(ReactiveFormsModule);
96
- // // or old fashion way
98
+ // // or the old-fashioned way
97
99
  // return TestBed.configureTestingModule({
98
100
  // imports: [
99
101
  // MockModule(SharedModule), // mock
@@ -126,7 +128,7 @@ describe('profile:builder', () => {
126
128
 
127
129
  expect(
128
130
  fixture.point.componentInstance,
129
- ).toEqual(assertion.any(ProfileComponent));
131
+ ).toEqual(jasmine.any(ProfileComponent));
130
132
  });
131
133
 
132
134
  // A test to ensure that the component listens
@@ -140,7 +142,7 @@ describe('profile:builder', () => {
140
142
  };
141
143
 
142
144
  // A spy to track save calls.
143
- // MockInstance helps to configure mock
145
+ // MockInstance helps configure mock
144
146
  // providers, declarations and modules
145
147
  // before their initialization and usage.
146
148
  // https://ng-mocks.sudo.eu/api/MockInstance
@@ -179,7 +181,7 @@ describe('profile:builder', () => {
179
181
  // https://ng-mocks.sudo.eu/api/ngMocks/trigger
180
182
  ngMocks.trigger(point, 'keyup.control.s');
181
183
 
182
- // The spy should be called with the user
184
+ // The spy should be called with the profile
183
185
  // and the random email address.
184
186
  expect(spySave).toHaveBeenCalledWith({
185
187
  email: 'test3@em.ail',
package/example.spec.ts CHANGED
@@ -17,8 +17,7 @@ import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';
17
17
 
18
18
  @Pipe({
19
19
  name: 'translate',
20
- ['standalone' as never /* TODO: remove after upgrade to a14 */]:
21
- false,
20
+ ['standalone' as never /* TODO: remove after upgrade to a14 */]: false,
22
21
  })
23
22
  class TranslatePipe implements PipeTransform {
24
23
  public transform(value: string): string {
@@ -31,8 +30,7 @@ class TranslatePipe implements PipeTransform {
31
30
  // Our main component that we want to test.
32
31
  @Component({
33
32
  selector: 'app-root',
34
- ['standalone' as never /* TODO: remove after upgrade to a14 */]:
35
- false,
33
+ ['standalone' as never /* TODO: remove after upgrade to a14 */]: false,
36
34
  template: `
37
35
  <app-header
38
36
  [showLogo]="true"
@@ -64,8 +62,7 @@ class AppComponent {
64
62
  // component with a respect of its inputs, outputs and ContentChild.
65
63
  @Component({
66
64
  selector: 'app-header',
67
- ['standalone' as never /* TODO: remove after upgrade to a14 */]:
68
- false,
65
+ ['standalone' as never /* TODO: remove after upgrade to a14 */]: false,
69
66
  template: `
70
67
  <a (click)="logo.emit()">
71
68
  <img src="assets/logo.png" *ngIf="showLogo" />
package/index.d.ts CHANGED
@@ -971,6 +971,20 @@ export declare function isNgDef(declaration: any): declaration is Type<any>;
971
971
  * ```
972
972
  */
973
973
  export declare const isNgInjectionToken: (token: any) => token is InjectionToken<any>;
974
+ export type MockInstanceTokenInit<T> = (instance: T | undefined, injector: Injector | undefined) => Partial<T> | Array<Partial<T>>;
975
+ export interface MockInstanceTokenConfig<T> {
976
+ /**
977
+ * @deprecated please pass the callback directly instead of config.
978
+ */
979
+ init?: MockInstanceTokenInit<T>;
980
+ }
981
+ export type MockInstanceClassInit<T> = (instance: T, injector: Injector | undefined) => void | Partial<T> | Array<Partial<T>>;
982
+ export interface MockInstanceClassConfig<T> {
983
+ /**
984
+ * @deprecated please pass the callback directly instead of config.
985
+ */
986
+ init?: MockInstanceClassInit<T>;
987
+ }
974
988
  /**
975
989
  * This signature of MockInstance lets customize the getter of a property.
976
990
  *
@@ -1018,11 +1032,10 @@ export declare function MockInstance<T extends object, K extends keyof T, S exte
1018
1032
  * MockInstance(webSocketToken, () => mockWebSocket);
1019
1033
  * ```
1020
1034
  */
1021
- export declare function MockInstance<T>(declaration: InjectionToken<T>, init?: (instance: T | undefined, injector: Injector | undefined) => Partial<T> | Array<Partial<T>>): void;
1035
+ export declare function MockInstance<T>(declaration: InjectionToken<T>, init?: MockInstanceTokenInit<T>): void;
1022
1036
  /**
1023
1037
  * This signature of MockInstance lets customize tokens with a callback.
1024
1038
  *
1025
- * @deprecated please pass the callback directly instead of config.
1026
1039
  * @see https://ng-mocks.sudo.eu/api/MockInstance
1027
1040
  *
1028
1041
  * ```ts
@@ -1031,9 +1044,7 @@ export declare function MockInstance<T>(declaration: InjectionToken<T>, init?: (
1031
1044
  * });
1032
1045
  * ```
1033
1046
  */
1034
- export declare function MockInstance<T>(declaration: InjectionToken<T>, config?: {
1035
- init?: (instance: T | undefined, injector: Injector | undefined) => Partial<T> | Array<Partial<T>>;
1036
- }): void;
1047
+ export declare function MockInstance<T>(declaration: InjectionToken<T>, config?: MockInstanceTokenConfig<T>): void;
1037
1048
  /**
1038
1049
  * This signature of MockInstance lets customize the instances of mock classes with a callback.
1039
1050
  * You can return a shape or change the instance.
@@ -1052,12 +1063,11 @@ export declare function MockInstance<T>(declaration: InjectionToken<T>, config?:
1052
1063
  * });
1053
1064
  * ```
1054
1065
  */
1055
- export declare function MockInstance<T>(declaration: AnyType<T>, init?: (instance: T, injector: Injector | undefined) => void | Partial<T> | Array<Partial<T>>): void;
1066
+ export declare function MockInstance<T>(declaration: AnyType<T>, init?: MockInstanceClassInit<T>): void;
1056
1067
  /**
1057
1068
  * This signature of MockInstance lets customize the instances of mock classes with a callback.
1058
1069
  * You can return a shape or change the instance.
1059
1070
  *
1060
- * @deprecated please pass the callback directly instead of config.
1061
1071
  * @see https://ng-mocks.sudo.eu/api/MockInstance
1062
1072
  *
1063
1073
  * ```ts
@@ -1076,9 +1086,7 @@ export declare function MockInstance<T>(declaration: AnyType<T>, init?: (instanc
1076
1086
  * });
1077
1087
  * ```
1078
1088
  */
1079
- export declare function MockInstance<T>(declaration: AnyType<T>, config?: {
1080
- init?: (instance: T, injector: Injector | undefined) => void | Partial<T> | Array<Partial<T>>;
1081
- }): void;
1089
+ export declare function MockInstance<T>(declaration: AnyType<T>, config?: MockInstanceClassConfig<T>): void;
1082
1090
  /**
1083
1091
  * Interface describes how to configure scopes for MockInstance.
1084
1092
  *
@@ -1540,6 +1548,9 @@ export interface IMockRenderFactoryOptions extends IMockRenderOptions {
1540
1548
  * @see https://ng-mocks.sudo.eu/api/MockRender
1541
1549
  */
1542
1550
  export interface MockedComponentFixture<C = any, F = DefaultRenderComponent<C>> extends ComponentFixture<F> {
1551
+ componentInstance: ComponentFixture<F>["componentInstance"];
1552
+ debugElement: ComponentFixture<F>["debugElement"] & MockedDebugElement<F>;
1553
+ nativeElement: ComponentFixture<F>["nativeElement"];
1543
1554
  point: MockedDebugElement<C>;
1544
1555
  }
1545
1556
  /**