Comments (3)
@GipHub123 thanks for the explanation, because I'm also encountering this issue. If I understand correctly, MockComponent
and MockComponents
mocks all components in the target component independently of the arguments for those functions?
Your comment about that you should probably mock MyComp2 as well, can be true, but is largely dependent of the test your are writing. Also using the MockBuilder forces you to rewrite the tests to work with the MockBuilder.
It would make more sense that MockComponent and MockComponents only mocks the actual components provided. So curious to hear from the maintainer whether this is a bug or not or what is the best way to work around this is using MockBuilder is not an option.
from ng-mocks.
To test standalone components, try setting up your test cases using MockBuilder
;
Check example: https://github.com/help-me-mom/ng-mocks/blob/master/examples/TestStandaloneComponent/test.spec.ts
beforeEach(async () => {
return MockBuilder(MyComp)
.keep(MyComp1)
.mock(MyComp2);
});
Here is another real life example;
beforeEach(async () => {
return MockBuilder(ButtonActionComponent)
.keep(MatButtonModule)
.keep(MatIconModule)
.keep(MatTooltipModule)
.keep(TranslateModule)
.mock(ComponentX);
});
You want to usually isolate test case meaning that better practice is to mock all components that are not necessary for your test case. In another words use should probably mock MyComp2 as well :)
from ng-mocks.
Your comment about that you should probably mock MyComp2 as well, can be true, but is largely dependent of the test your are writing. Also using the MockBuilder forces you to rewrite the tests to work with the MockBuilder.
@screambeard Yes I totally agree with you 👍 I was trying to say to that mocking makes usually more sense.
Also using the MockBuilder forces you to rewrite the tests to work with the MockBuilder.
Yes. Rewriting tests setup can be haunting task. Been there 😄
from ng-mocks.
Related Issues (20)
- support vitest
- ngMocksUniverse.global
- Bug: MockMiddleware{Index} HOT 1
- update links in the repo HOT 2
- update sponsor links in the repo HOT 2
- Bug: cannot set return value of DI'ed pipe HOT 1
- Bug: `.keep(ReactiveFormsModule)` does not actually keep HOT 4
- Bug: Angular 17.1.0 `input.required()` issues HOT 15
- Feature Request: Documentation for functional route guards without the use of NgModule
- Bug: Injection of mocked service fails for nested service ... but only sometimes ...
- Bug: cannot `.replace()` a component that has an abstract base class HOT 3
- Bug: formatHtml on MockedComponentFixture / DebugElement won't give expected value
- Bug: try to avoid recursive parsing when a standalone component imports itself
- Bug: Incompatibility of MockComponent with new viewChild signal function HOT 8
- Bug: MockRender throws an error on mat-tab HOT 3
- MockComponent function set Signal Inputs as Decorator Inputs
- Bug: Erroneous test setup due to the usage of contentChildren HOT 3
- Feature Request: release angular18 version HOT 8
- Bug: fail CI on missing package-lock.json sync HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ng-mocks.