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

Support passing template in factory #299

Closed
dev054 opened this issue Apr 28, 2020 · 3 comments
Closed

Support passing template in factory #299

dev054 opened this issue Apr 28, 2020 · 3 comments

Comments

@dev054
Copy link

dev054 commented Apr 28, 2020

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[x] Support request
[ ] Other... Please describe:

Current behavior

I noticed that SpectatorDirectiveOptions supports (or at least is what the interface tell us) a "fixed" template, so I tried to use it:

describe('MyDirective', () => {
  let spectator: SpectatorDirective<MyDirective>;
  const createDirective = createDirectiveFactory({
    directive: MyDirective,
    template: '<input myDirective>',
  });

  test('should do something', () => {
    // Expected 1 arguments, but got 0.ts(2554)
    // spectator-directive.d.ts(22, 70): An argument for 'typeOrOptions' was not provided.
    spectator = createDirective();
  });
});

... however it gives the error I have commented out. Since it isn't allowed to have a "fixed" template as createDirective always expect a template, I wonder why exists this option.

Note that the same happens with SpectatorHostOptions and with SpectatorPipeOptions:

describe('MyPipe', () => {
  const createPipe = createPipeFactory({
    pipe: MyPipe,
    template: '{{ input | myPipe }}',
  });

  test('should do something', () => {
    const { element } = createPipe({
      hostProps: {
        input: 'text',
      },
    });
    expect(element).toHaveExactText('text');
  });

... the test fails because it doesn't recognizes the template (the input is always empty. No matter the input I pass).


It's not clear in docs how to use, or even if it's possible to use this feature.

Expected behavior

I'd expect to know if it's possible to use it.

Environment


Angular CLI: 9.1.3
Node: 13.7.0
OS: darwin x64

Angular: 9.1.3
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.901.3
@angular-devkit/build-angular      0.901.3
@angular-devkit/build-ng-packagr   0.901.3
@angular-devkit/build-optimizer    0.901.3
@angular-devkit/build-webpack      0.901.3
@angular-devkit/core               9.1.3
@angular-devkit/schematics         9.1.3
@ngtools/webpack                   9.1.3
@schematics/angular                9.1.3
@schematics/update                 0.901.3
ng-packagr                         9.1.1
rxjs                               6.5.5
typescript                         3.8.3
webpack                            4.42.0
@NetanelBasal
Copy link
Member

NetanelBasal commented Apr 30, 2020

It's legacy code, and I'll remove it. Thanks. You can do:

beforeEach(() => (spectator = createPipe(`{{ [1, 2, 3] | sum }}`)));

@dev054
Copy link
Author

dev054 commented Apr 30, 2020

It's legacy code, and I'll remove it. Thanks. You can do:

beforeEach(() => (spectator = createPipe(`{{ [1, 2, 3] | sum }}`)));

Hey @NetanelBasal thanks for the response. Oh, so it should be removed from the 3 interfaces?


Btw, your suggestion is a little bit different to what I was trying to accomplish. I was trying to have a fixed template and manipulate the props in each test... but as now you said that it's deprecated... it seems that the only way possible is by creating a component.


PS: Shouldn't this issue remain open to track this for future removal?

@NetanelBasal NetanelBasal reopened this May 1, 2020
@NetanelBasal
Copy link
Member

After re-examining the code, I think we can add this as a feature. Currently, we ignore the template passed in the factory. Do you want to create a PR?

@NetanelBasal NetanelBasal changed the title Template option in SpectatorDirectiveOptions, SpectatorPipeOptions and SpectatorHostOptions Support passing template factory May 1, 2020
@NetanelBasal NetanelBasal changed the title Support passing template factory Support passing template in factory May 1, 2020
kremerd pushed a commit to kremerd/spectator that referenced this issue May 23, 2020
kremerd pushed a commit to kremerd/spectator that referenced this issue May 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants