Skip to content

Commit

Permalink
Merge pull request #4578 from satanTime/issues/4577
Browse files Browse the repository at this point in the history
docs: how to fix Error NG0300 #4577
  • Loading branch information
satanTime authored Dec 24, 2022
2 parents 8a6109a + 8c204e7 commit 8352107
Show file tree
Hide file tree
Showing 68 changed files with 316 additions and 276 deletions.
8 changes: 4 additions & 4 deletions docs/articles/api/MockBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ beforeEach(() => {
```

In case of `RouterTestingModule`,
we need to use [`.keep`](#keep) for both of the modules and [`NG_MOCKS_ROOT_PROVIDERS`](#ngmocksrootproviders-token),
we need to use [`.keep`](#keep) for both of the modules and [`NG_MOCKS_ROOT_PROVIDERS`](#ng_mocks_root_providers-token),
and to pass an empty array into `.withRoutes`.
[`NG_MOCKS_ROOT_PROVIDERS`](#ngmocksrootproviders-token) is needed,
[`NG_MOCKS_ROOT_PROVIDERS`](#ng_mocks_root_providers-token) is needed,
because `RouterModule` has many root dependencies which should be also kept.

```ts
Expand Down Expand Up @@ -296,7 +296,7 @@ beforeEach(() => {
## Config

You can customize default behavior of mock things.
Also, it can be done globally via [`ngMocks.defaultConfig()`](./ngMocks/defaultConfig.md) to avoid repetitions.
Also, it can be done globally via [`ngMocks.defaultConfig()`](ngMocks/defaultConfig.md) to avoid repetitions.

### `precise` flag

Expand Down Expand Up @@ -524,7 +524,7 @@ All other root providers will be replaced with their mocks, even for kept declar

## Factory function

You might be using other [testing frameworks for angular](../extra/with-3rd-party),
You might be using other [testing frameworks for angular](/extra/with-3rd-party.md),
such as [`@ngneat/spectator`](https://www.npmjs.com/package/@ngneat/spectator)
or [`@testing-library/angular`](https://www.npmjs.com/package/@testing-library/angular).

Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/MockComponent.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The class of a mock component has:

:::tip
Information about mocking FormControl, ControlValueAccessor, Validator and AsyncValidator
is in [a different section](../extra/mock-form-controls.md).
is in [a different section](/extra/mock-form-controls.md).
:::

## Simple example
Expand Down Expand Up @@ -117,7 +117,7 @@ TestBed.configureTestingModule({
});
```

[`MockBuilder`](./MockBuilder.md) also supports standalone components
[`MockBuilder`](MockBuilder.md) also supports standalone components
and allows to mock their imports only for shallow rendering.

## Advanced example
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/MockDirective.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ A mock directive has:

:::tip
Information about mocking FormControl, ControlValueAccessor, Validator and AsyncValidator
is in [a different section](../extra/mock-form-controls.md).
is in [a different section](/extra/mock-form-controls.md).
:::

## Simple example
Expand Down Expand Up @@ -118,7 +118,7 @@ TestBed.configureTestingModule({
});
```

[`MockBuilder`](./MockBuilder.md) recognizes and handles standalone directives.
[`MockBuilder`](MockBuilder.md) recognizes and handles standalone directives.
Also, it allows to mock their imports only for shallow testing.

## Advanced example with attribute directives
Expand Down
16 changes: 8 additions & 8 deletions docs/articles/api/MockInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ It is useful, when we want to configure spies before their usage.
It supports: modules, components, directives, pipes, services and tokens.

The mocks should be created by:
- [`MockBuilder`](../api/MockBuilder.md)
- [`MockModule`](../api/MockModule.md)
- [`MockComponent`](../api/MockComponent.md)
- [`MockDirective`](../api/MockDirective.md)
- [`MockProvider`](../api/MockProvider.md)
- [`MockBuilder`](/api/MockBuilder.md)
- [`MockModule`](/api/MockModule.md)
- [`MockComponent`](/api/MockComponent.md)
- [`MockDirective`](/api/MockDirective.md)
- [`MockProvider`](/api/MockProvider.md)

## Define customizations

Expand Down Expand Up @@ -219,8 +219,8 @@ it('test 3', () => {

It is definitely the right time to use it, if a test fails like:

- [TypeError: Cannot read property 'subscribe' of undefined](../troubleshooting/read-property-of-undefined.md)
- [TypeError: Cannot read property 'pipe' of undefined](../troubleshooting/read-property-of-undefined.md)
- [TypeError: Cannot read property 'subscribe' of undefined](/troubleshooting/read-property-of-undefined.md)
- [TypeError: Cannot read property 'pipe' of undefined](/troubleshooting/read-property-of-undefined.md)
- or any other issue like reading properties or calling methods of undefined

Or we want to customize a mock declaration which is accessed via:
Expand All @@ -244,7 +244,7 @@ class RealComponent implements AfterViewInit {

When we test `RealComponent` we would like to have a mock `ChildComponent`,
and it would mean, if we replaced it with a mock `ChildComponent` then its `update$` would return `undefined`,
therefore our test would fail in `ngAfterViewInit` because of [`TypeError: Cannot read property 'subscribe' of undefined`](../troubleshooting/read-property-of-undefined.md).
therefore our test would fail in `ngAfterViewInit` because of [`TypeError: Cannot read property 'subscribe' of undefined`](/troubleshooting/read-property-of-undefined.md).

In our case, we have a component instance created by Angular, and does not look like `TestBed` provides
a solution here. That is where `ng-mocks` helps again with the `MockInstance` helper function.
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/MockModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ A mock module provides:
- respect of tokens with a `useExisting` definition
- empty objects instead of tokens with a `helperUseFactory` definition
- base primitives instead of tokens with a `useValue` definition
- mocks of tokens with a `useValue` definition can read in the section called [How to fix `Type is part of the declarations of 2 modules`](../troubleshooting/declarations-of-2-modules.md).
- mocks of tokens with a `useValue` definition can read in the section called [How to fix `Type is part of the declarations of 2 modules`](/troubleshooting/declarations-of-2-modules.md).

:::danger
Do not use `MockModule` on modules which declare the tested declaration.
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/MockPipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ TestBed.configureTestingModule({
});
```

[`MockBuilder`](./MockBuilder.md) also supports and correctly works with standalone pipes.
[`MockBuilder`](MockBuilder.md) also supports and correctly works with standalone pipes.

## Advanced example

Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/MockProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ describe('Test', () => {
:::warning Please note
The most common error developers meet, when they create mock services, is "**TypeError: Cannot read property 'subscribe' of undefined**".

If we are encountering it too, please read a section called [How to fix TypeError: Cannot read property 'subscribe' of undefined](../troubleshooting/read-property-of-undefined.md).
If we are encountering it too, please read a section called [How to fix TypeError: Cannot read property 'subscribe' of undefined](/troubleshooting/read-property-of-undefined.md).
:::

## Advanced example
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/MockRender.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ usage of `MockRender` after usage of `TestBed.get`, `TestBed.inject`, `TestBed.c
triggers an error about dirty `TestBed`.

However, it is still possible to use `MockRender` more than once in a test.
It requires a reset of `TestBed` (check [`ngMocks.flushTestBed`](./ngMocks/flushTestBed.md)).
It requires a reset of `TestBed` (check [`ngMocks.flushTestBed`](ngMocks/flushTestBed.md)).
Please note, that this makes all existing service instances obsolete.

```ts
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/MockService.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If you are here in order to mock **a service** or **a token**,
please read [corresponding section about MockProvider](MockProvider.md).

If you want to change default mock behavior,
please read [how to customize mocks](../extra/customize-mocks.md).
please read [how to customize mocks](/extra/customize-mocks.md).
:::

If you **need a mock object of a class** which does not belong to Angular declarations, for instance `HTMLInputElement`,
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/change.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.change
description: Documentation about ngMocks.change from ng-mocks library
description: Documentation about `ngMocks.change` from ng-mocks library
---

`ngMocks.change` helps to **simulate external changes of a form control**.
Expand Down Expand Up @@ -29,7 +29,7 @@ ngMocks.change(el, 123);
expect(component.value).toEqual(123);
```

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

```ts
ngMocks.change('input', 123);
Expand Down
8 changes: 4 additions & 4 deletions docs/articles/api/ngMocks/click.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.click
description: Documentation about ngMocks.click, a simple tool to click any element in unit tests
description: Documentation about `ngMocks.click`, a simple tool to click any element in unit tests
---

There are several ways how to click an element in Angular unit tests.
Expand All @@ -27,7 +27,7 @@ ngMocks.click(el.nativeElement, {
});
```

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

```ts
ngMocks.click('a');
Expand All @@ -42,5 +42,5 @@ ngMocks.click(['data-role']);
ngMocks.click(['data-role', 'link']);
```

Under the hood `ngMocks.click` uses [`ngMocks.trigger`](./trigger.md),
therefore all features of [`ngMocks.trigger`](./trigger.md) can be used.
Under the hood `ngMocks.click` uses [`ngMocks.trigger`](trigger.md),
therefore all features of [`ngMocks.trigger`](trigger.md) can be used.
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/crawl.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.crawl
description: Documentation about ngMocks.crawl from ng-mocks library
description: Documentation about `ngMocks.crawl` from ng-mocks library
---

`ngMocks.crawl` is a special function which goes through the passed `DebugNode` or `DebugElement`,
Expand All @@ -26,7 +26,7 @@ a different amount of text nodes for the same template.
ngMocks.crawl(debugElement, callback, textNodes);
```

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

```ts
ngMocks.crawl('div.root', callback, textNodes);
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/defaultConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: ngMocks.defaultConfig
description: Documentation about ngMocks.defaultConfig from ng-mocks library
---

Sets default config for mocks in [`MockBuilder`](../MockBuilder.md#config).
Sets default config for mocks in [`MockBuilder`](/api/MockBuilder.md#config).

- `ngMocks.defaultConfig( Component, config )` - sets a default config for a component
- `ngMocks.defaultConfig( Directive, config )` - sets a default config for a directive
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/event.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.event
description: Documentation about ngMocks.event, a simple interface to create custom events in unit tests
description: Documentation about `ngMocks.event`, a simple interface to create custom events in unit tests
---

`ngMocks.event` solves the legacy of IE11, when an event object cannot be created via `new CustomEvent`, but via `document.createEvent`.
Expand All @@ -14,4 +14,4 @@ const event = ngMocks.event('click', {
});
```

The created event can be dispatched via [`ngMocks.trigger`](./trigger.md#custom-events).
The created event can be dispatched via [`ngMocks.trigger`](trigger.md#custom-events).
6 changes: 3 additions & 3 deletions docs/articles/api/ngMocks/faster.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.faster
description: Documentation about ngMocks.faster from ng-mocks library
description: Documentation about `ngMocks.faster` from ng-mocks library
---

There is a `ngMocks.faster` feature that optimizes setup of similar test modules between tests
Expand Down Expand Up @@ -35,7 +35,7 @@ describe('performance:correct', () => {
If a test creates spies in `beforeEach` then this should be tuned,
because `ngMocks.faster` will detect this difference and display a notice.

A possible solution is usage of [MockInstance](../MockInstance.md) instead of manual declaration,
A possible solution is usage of [MockInstance](/api/MockInstance.md) instead of manual declaration,
or to move creation of spies outside of `beforeEach`.

## Example of MockInstance
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('beforeEach:manual-spy', () => {

## MockRender

Usage of `ngMocks.faster()` covers [`MockRender`](../MockRender.md) too.
Usage of `ngMocks.faster()` covers [`MockRender`](/api/MockRender.md) too.

With its help, `MockRender` can be called in either `beforeEach` or `beforeAll`.
`beforeAll` won't reset its fixture after a test, and the fixture can be used in the next test.
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/find.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.find
description: Documentation about ngMocks.find from ng-mocks library
description: Documentation about `ngMocks.find` from ng-mocks library
---

Returns a found DebugElement which belongs to a component with the correctly typed componentInstance,
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/findInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If the element is not specified, then the current fixture is used.
- `ngMocks.findInstance( fixture?, directive, notFoundValue? )`
- `ngMocks.findInstance( debugElement?, directive, notFoundValue? )`

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

- `ngMocks.findInstance( cssSelector?, directive, notFoundValue? )`

Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/findInstances.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ If the element is not specified, then the current fixture is used.
- `ngMocks.findInstances( fixture?, directive )`
- `ngMocks.findInstances( debugElement?, directive )`

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

- `ngMocks.findInstances( cssSelector?, directive )`

Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/findTemplateRef.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If the element is not specified, then the current fixture is used.
- `ngMocks.findTemplateRef( debugElement?, id, notFoundValue? )`
- `ngMocks.findTemplateRef( debugElement?, [attribute, value?], notFoundValue? )`

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

- `ngMocks.findTemplateRef( cssSelector?, [attribute, value?], notFoundValue? )`

Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/findTemplateRefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ If the element is not specified, then the current fixture is used.
- `ngMocks.findTemplateRefs( debugElement?, id )`
- `ngMocks.findTemplateRefs( debugElement?, [attribute, value?] )`

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

- `ngMocks.findTemplateRefs( cssSelector?, [attribute, value?] )`

Expand Down Expand Up @@ -40,4 +40,4 @@ const onlyFooters = ngMocks.findTemplateRefs(['myTpl', 'footer']);
const empty = ngMocks.findTemplateRefs(['myTpl', 'body']);
```

More information can be found in [`ngMocks.findTemplateRef`](./findTemplateRef.md).
More information can be found in [`ngMocks.findTemplateRef`](findTemplateRef.md).
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/formatHtml.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ becomes

## ng-container

A cool thing is that `ngMocks.formatHtml` uses [`ngMocks.crawl`](./crawl.md) under the hood
A cool thing is that `ngMocks.formatHtml` uses [`ngMocks.crawl`](crawl.md) under the hood
and respects `ng-container`.

so if we have a pointer to `ng-container`, we can assert its content.
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/formatText.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ header 12

## ng-container

A cool thing is that `ngMocks.formatText` uses [`ngMocks.crawl`](./crawl.md) under the hood
A cool thing is that `ngMocks.formatText` uses [`ngMocks.crawl`](crawl.md) under the hood
and respects `ng-container`.

so if we have a pointer to `ng-container`, we can assert its content.
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/get.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.get
description: Documentation about ngMocks.get from ng-mocks library
description: Documentation about `ngMocks.get` from ng-mocks library
---

Returns a component, directive, service or token, which can be attribute or structural directives,
Expand All @@ -25,7 +25,7 @@ const service = ngMocks.get(MyServiceType);
```


or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

- `ngMocks.get( cssSelector, Directive, notFoundValue? )`
```ts
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/guts.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: ngMocks.guts
description: Documentation about ngMocks.guts from ng-mocks library
description: Documentation about `ngMocks.guts` from ng-mocks library
---

Generates and returns metadata for `TestBed` module.
Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/hide.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: ngMocks.hide
description: Documentation about ngMocks.hide from ng-mocks library
description: Documentation about `ngMocks.hide` from ng-mocks library
---

`ngMocks.hide` hides what [`ngMocks.render`](./render.md) has rendered.
`ngMocks.hide` hides what [`ngMocks.render`](render.md) has rendered.

```ts
ngMocks.hide(declarationInst);
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/api/ngMocks/ignoreOnConsole.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: ngMocks.ignoreOnConsole
description: A way to suppress console logs in Angular unit tests
---

`ngMocks.ignoreOnConsole` suppresses `console.log` with a spy (if [auto spy](../../extra/auto-spy.md) is being used).
`ngMocks.ignoreOnConsole` suppresses `console.log` with a spy (if [auto spy](/extra/auto-spy.md) is being used).

`ngMocks.ignoreOnConsole` suppresses the functions for the current test suite in `beforeAll` and restores in `afterAll`.

Expand Down
4 changes: 2 additions & 2 deletions docs/articles/api/ngMocks/input.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: ngMocks.input
description: Documentation about ngMocks.input from ng-mocks library
description: Documentation about `ngMocks.input` from ng-mocks library
---

Returns value of an `input` of an element.
It avoids the issue of knowing the name of a component / directive the input belongs to.

- `ngMocks.input( debugElement, input, notFoundValue? )`

or simply with selectors which are supported by [`ngMocks.find`](./find.md).
or simply with selectors which are supported by [`ngMocks.find`](find.md).

- `ngMocks.input( cssSelector, input, notFoundValue? )`

Expand Down
Loading

0 comments on commit 8352107

Please sign in to comment.