Giter Site home page Giter Site logo

Comments (9)

satanTime avatar satanTime commented on May 17, 2024 2

I've implemented helper function which works together with attribute and structural directives:

// Extracting mock.
const debugElement = fixture.debugElement.query(By.css('div'));
const directive = MockHelper.getDirective(
  debugElement,
  MockDirective(CustomNgIfDirective),
);
expect(directive).toBeTruthy();
if (!directive) {
  return;
}

from ng-mocks.

ike18t avatar ike18t commented on May 17, 2024

Maybe throw something on the directive host?

from ng-mocks.

ike18t avatar ike18t commented on May 17, 2024

Hey @satanTime

I've been messing around with this trying to come up with a solution and nothing I've tried has worked out for me. Do you happen to have any ideas on how this could be accomplished?

from ng-mocks.

satanTime avatar satanTime commented on May 17, 2024

Hi. Very good question.

I've never written any structural directive. But if it's true as docs explain: https://angular.io/guide/structural-directives#inside-ngfor (they're syntax sugar), I think your library already has almost everything, except a way to pass context to ng-template override values in let-... syntax.

The same thing I use in some my templates with let- and had idea one day to investigate how we can mock let-..., currently I don't cover 100% components with let-... in ng-template.

Once we have way to control let-... I think we can control structural directives too.

from ng-mocks.

ike18t avatar ike18t commented on May 17, 2024

It does have support for structural directives but the problem is that these directives aren't available on the host element's injector, unlike normal attribute directives. This makes getting the directive back out of the debug element in the test to assert on inputs challenging (if possible).

At this point I'd settle with throwing a data attribute on the host with the directive name and inputs but I had issues with that as well. 🤷🏻‍♂️

from ng-mocks.

satanTime avatar satanTime commented on May 17, 2024

Aha :) good to know. Let me dive inside one day to check how it works. Is there any branch where I could check what you'd tried before?

from ng-mocks.

ike18t avatar ike18t commented on May 17, 2024

Good luck! https://github.com/ike18t/ng-mocks/tree/structural

from ng-mocks.

satanTime avatar satanTime commented on May 17, 2024

from ng-mocks.

satanTime avatar satanTime commented on May 17, 2024

Hi @ike18t, how do you do?

Might you review possible solution? #40
Please don't merge it, I want to find a way how to select related directive in more easier way as you have in your example: const debugElement = fixture.debugElement.query(By.css('#example-structural-directive'));, instead of iterating through everything.

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.