akveo / akveo/nebular

Better support for end-user automated testing

Aberta
#2,027 1 comentário 7 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
8.1k
Forks
1.5k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

### Issue type

**I'm submitting a ...** (check one with "x")

* [ ] bug report
* [x] feature request

### Issue description

**Current behavior:**
When using Nb libs, configuring the TestBed for components and modules that use NbThemes or layout components is not straight-forward, nor is there guidance in the available docs on how to go about pulling all the necessary DI pieces in to get the TestBed to compile. Or, if such a thing does exist (a testing helper module, or docs on how to test with the Nebular packages), I couldn't find it after 10 minutes of searching the website or repo.

**Impact:**
- Users with contractual code coverage minimums may abandon the framework due to testing difficulties
- Adding this kind of support is a major selling point
- Having this feature would create simpler internal tests for the actual source code as well

**Expected behavior:**
Similar to how Angular offers the [HttpClientTestingModule](https://angular.io/api/common/http/testing/HttpClientTestingModule) and [RouterTestingModule](https://angular.io/api/router/testing/RouterTestingModule), the Nebular NPM packages should offer testing modules that handle the problem of properly mocking the internal workings so end-users don't have to.

```typescript
imports: [NbLayoutTestingModule, ...]
```

**Steps to reproduce:**
1. Make a new Angular App, import `@nebular/
1. Make a component that uses the `NbLayoutComponent`.
1. In the component's spec file, import `NbLayoutModule`
1. Note the NullInjector errors that pop up:

```
Chrome 77.0.3865 (Windows 10.0.0) AppComponent should create the app FAILED
NullInjectorError: StaticInjectorError(DynamicTestModule)[NbLayoutComponent -> NbThemeService]:
StaticInjectorError(Platform: core)[NbLayoutComponent -> NbThemeService]:
NullInjectorError: No provider for NbThemeService!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'NbLayoutComponent', Function ], ngDebugContext: DebugContext_({ view: Object({ def: Object({ factory: Function, nodeFlags: 54771713,
rootNodeFlags: 33554433, nodeMatchedQueries: 0, flags: 0, nodes: [ Object({ nodeIndex: 0, parent: null, renderParent: null, bindingIndex: 0, outputIndex: 0, checkIndex: 0, flags: 33554433, childFlags: 54771713, directChildFlags: 37928961, childMatchedQueries: 0, matchedQueries: Object({ }), matchedQueryIds: 0, references: Object({ }), ngContentIndex: null, childCount: 11, bindings: [ Object({ flags: 2, ns: '', name: 'window-mode', nonMinifiedName: 'window-mode', securityContext: undefined, suffix: undefined }), Object({ flags: 2, ns: '', name: 'with-scroll', nonMinifiedName: 'with-scroll', securityContext: undefined, suffix: undefined }), Object({ flags: 2, ns: '', name: 'with-subheader', nonMinifiedName: 'with-subheader', securityContext: undefined, suffix: undefined }) ], bindingFlags: 2, outputs: [ ...
at
at NullInjector.get (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:855:1)
at resolveToken (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17513:1)
at tryResolveToken (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17439:1)
at StaticInjector.get (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17265:1)
at resolveToken (http://localhost:9877/_karma_webpack_/node_modules/@angular/core/fesm2015/core.js:17513:1)
```

**Related code:**
The fairly trivial app found [here](https://github.com/fireship-io/angular-tic-tac-toe) is a great example. It's a tic-tac-toe app, a tutorial for beginners, that can't easily handle unit tests because of this.

In short, the following helper module really shouldn't be necessary, nor should it be up to consumers to have to piece it all together.

```typescript
@NgModule({
providers: [
NbThemeService,
// Required by NbThemeService
NbMediaBreakpointsService,
{ provide: NB_THEME_OPTIONS, useValue: { name: 'default' } },
{ provide: NB_MEDIA_BREAKPOINTS, useValue: DEFAULT_MEDIA_BREAKPOINTS },
{ provide: NB_JS_THEMES, useValue: [] },
{ provide: NB_BUILT_IN_JS_THEMES, useValue: BUILT_IN_THEMES },
NbJSThemesRegistry,
// NbSpinnerService
NbSpinnerService,
// Required by NbLayoutComponent
{ provide: NB_DOCUMENT, useValue: document },
{ provide: NB_WINDOW, useValue: window },
NbLayoutDirectionService,
NbLayoutScrollService,
NbLayoutRulerService,
NbOverlayContainerAdapter
]
})
export class NebularTestingModule {}
```

### Other information:

**npm, node, OS, Browser**
N/A

**Angular, Nebular**
N/A

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.