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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializers should be more useful #967

Open
Lonli-Lokli opened this issue Jul 2, 2021 · 2 comments
Open

Serializers should be more useful #967

Lonli-Lokli opened this issue Jul 2, 2021 · 2 comments
Labels
馃殌 Feature Request new suggested feature

Comments

@Lonli-Lokli
Copy link

馃殌 Feature Proposal

Currently all object props are serialized as Object, which do not have any sense with snapshots

Motivation

Real serializer will help to increase real coverage with tests

Example

child

@Component({
  selector: 'test-sample',
  templateUrl: './sample.component.html',
  styleUrls: ['./sample.component.scss']
})
export class SampleComponent {

  @Input()
  public user!: {name: string};
}

parent

<header class="flex">
  <h1>Welcome to {{ title }}!</h1>
</header>
<main>
  <test-sample [user]="current"></test-sample>
</main>


@Component({
  selector: 'test-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  title = 'test';

  public current: {name: string} = { name: 'hero' }
}

produce this snapshot


<test-root
  __ngContext__={[Function LRootView]}
  current={[Function Object]}
  title={[Function String]}
>
  <header
    class="flex"
  >
    <h1>
      
    </h1>
  </header><main>
    <test-sample>
      <p>
        sample works!
      </p>
    </test-sample>
  </main>
</test-root>

So instead of
current={[Function Object]}
I was hoping to see
current={ name: 'hero' }

@Lonli-Lokli Lonli-Lokli added the 馃殌 Feature Request new suggested feature label Jul 2, 2021
@intellix
Copy link
Contributor

intellix commented May 16, 2022

Another thing I'd love to see is removal of private services being printed on the element as it makes maintaining snapshots on any injection really annoying and adds nothing as far as I can think.

constructor(private seoService: SeoService) {
  seoService.addMeta(...)
}

Ends up adding to the snapshot:

<cw-root
  seoService={[Function SeoService]}
>

But since it's not publically available to the view then I'm not sure what it adds to show it on the host element.

Currently I do:

expect(fixture).toMatchSnapshot();

But maybe we should be doing (which removes the host element from the snapshot). The problem with this though is that if you do add things to the host, they won't get snapshotted/tested:

expect(fixture.nativeElement).toMatchSnapshot();

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 16, 2022

PR is welcome:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃殌 Feature Request new suggested feature
Projects
None yet
Development

No branches or pull requests

3 participants