Skip to content

Commit

Permalink
fix(core): broken query selectors are properly normalized #567
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed May 18, 2021
1 parent 8614586 commit 9c1ea70
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default (queries?: Record<keyof any, any>): string => {
continue;
}
if (typeof query.selector === 'string') {
const selector = query.selector.replace(new RegExp('[^a-z0-9-_]+', 'mg'), ' ').trim().replace(' ', '_');
const selector = query.selector.replace(new RegExp('[^a-zA-Z0-9_]', 'mg'), '_');
queries[`__mockView_key_${selector}`] = new ViewChild(`key_${selector}`, viewChildArgs);
queries[`__mockTpl_key_${selector}`] = query;
parts.push(viewChildTemplate(selector, 'key'));
Expand Down
19 changes: 19 additions & 0 deletions tests/issue-567/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, ContentChild, TemplateRef } from '@angular/core';
import { MockBuilder, MockRender } from 'ng-mocks';

@Component({
selector: 'target',
template: '<ng-content></ng-content>',
})
class TargetComponent {
@ContentChild('s-e_-_ri23sTo 12 o#ltTem_~_plate_', {} as any)
public readonly seriesTooltipTemplate?: TemplateRef<any>;
}

describe('issue-567', () => {
beforeEach(() => MockBuilder(null, TargetComponent));

it('does not fail on seriesTooltipTemplate', () => {
expect(() => MockRender(TargetComponent)).not.toThrow();
});
});

0 comments on commit 9c1ea70

Please sign in to comment.