Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking internal package components #60

Closed
undsoft opened this issue Jul 17, 2019 · 4 comments · Fixed by #91
Closed

Mocking internal package components #60

undsoft opened this issue Jul 17, 2019 · 4 comments · Fixed by #91
Assignees

Comments

@undsoft
Copy link

undsoft commented Jul 17, 2019

Hi,

This may be two issues, but I'm trying to solve 1 problem.
Out project is split into several repos and they all consume modules from a core repo, which is build as an Angular package.

The problem is that this core repo only exposes modules, but not components.
Therefore I cannot do MockComponent(SomeComponent).

When I try to mock the whole module, I get weird errors like this:

Failed: Cannot read property 'reference' of null
TypeError: Cannot read property 'reference' of null
at singleProviderDef (node_modules/@angular/compiler/fesm5/compiler.js:19777:1)
at providerDef (node_modules/@angular/compiler/fesm5/compiler.js:19729:1)
at ViewBuilder.push../node_modules/@angular/compiler/fesm5/compiler.js.ViewBuilder._visitProviderOrDirective (node_modules/@angular/compiler/fesm5/compiler.js:22060:1)
at ViewBuilder.push../node_modules/@angular/compiler/fesm5/compiler.js.ViewBuilder._visitDirective (node_modules/@angular/compiler/fesm5/compiler.js:21954:1)
at node_modules/@angular/compiler/fesm5/compiler.js:21879:1

I don't see anything special about this module. Some of the other modules can be mocked.

My suggestion would be to allow MockComponents to be created from selector.

@satanTime
Copy link
Member

Hi @undsoft, might you provide more info, or maybe a code sample of the issue?
I think next setup should work for you:

    TestBed.configureTestingModule({
      imports: [MockModule(Package1Module), MockModule(Package2Module)],
      declarations: [AnyComponentYouWantToTestComponent],
      providers: []
    });

@satanTime satanTime linked a pull request Mar 9, 2020 that will close this issue
17 tasks
@satanTime satanTime self-assigned this Mar 9, 2020
@satanTime satanTime mentioned this issue Mar 21, 2020
17 tasks
@satanTime
Copy link
Member

Hi @undsoft,

might you test the issue on 10.0.0-alpha.0 with the MockBuilder https://www.npmjs.com/package/ng-mocks/v/10.0.0-alpha.0#mockbuilder ?

@satanTime
Copy link
Member

Hi @undsoft, have you tried beta version? 10.0.0-alpha.3 is the latest now.
Please let me know your feedback.

@satanTime
Copy link
Member

I'm closing the issue due to no feedback, feel free to reopen it if you meet any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants