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

formatText #314

Closed
satanTime opened this issue Mar 19, 2021 · 1 comment · Fixed by #318
Closed

formatText #314

satanTime opened this issue Mar 19, 2021 · 1 comment · Fixed by #318

Comments

@satanTime
Copy link
Member

There is ngMocks.formatHtml, and I've seen that in jest innerText doesn't work. At least, for me its value was always empty.

Therefore, to add a helper to get only formatted text makes sense.

But, responsibility how to find related debugElements and debugNodes, I would suggest to keep outside of this function.

Own helpers can be like that

const text = selector => ngMocks.formatText(ngMocks.find(selector));

expect(text('div span')).toEqual('Text 1');
const allText = selector => ngMocks.findAll(selector)
  .map(ngMocks.formatText);

expect(allText('div span')).toEqual(['Text 1', 'Text 2', 'Text 3']);
const allTextTrim = selector => ngMocks.findAll(selector)
  .map(ngMocks.formatText)
  .map(v => v.trim());

expect(allText('div span')).toEqual(['Text 1', 'Text 2', 'Text 3']);

Idea behind own helper function is that someone may want to lowercase / uppercase text or remove all spaces etc. And to cover all possible cases in ng-mocks can end up with lots of helpers which might be complicated to maintain.

satanTime added a commit that referenced this issue Mar 21, 2021
satanTime added a commit that referenced this issue Mar 21, 2021
@satanTime
Copy link
Member Author

v11.10.0 has been released and contains a fix for the issue. Feel free to reopen the issue or to submit a new one if you meet any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant