Coder Social home page Coder Social logo

Comments (3)

screambeard avatar screambeard commented on June 14, 2024 2

@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.

GipHub123 avatar GipHub123 commented on June 14, 2024 1

@Kogs

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.

GipHub123 avatar GipHub123 commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.