ngx-translate-extract/tests/parsers/utils.spec.ts

66 lines
1.7 KiB
TypeScript
Raw Permalink Normal View History

import { expect } from 'chai';
import { isPathAngularComponent, extractComponentInlineTemplate } from '../../src/utils/utils';
describe('Utils', () => {
it('should recognize js extension as angular component', () => {
const result = isPathAngularComponent('test.js');
expect(result).to.equal(true);
});
it('should recognize ts extension as angular component', () => {
const result = isPathAngularComponent('test.ts');
expect(result).to.equal(true);
});
it('should not recognize html extension as angular component', () => {
const result = isPathAngularComponent('test.html');
expect(result).to.equal(false);
});
it('should extract inline template', () => {
const contents = `
@Component({
selector: 'test',
template: '<p translate>Hello World</p>'
})
export class TestComponent { }
`;
const template = extractComponentInlineTemplate(contents);
expect(template).to.equal('<p translate>Hello World</p>');
});
2019-06-13 12:59:36 +03:00
it('should extract inline template without html', () => {
const contents = `
@Component({
selector: 'test',
2019-06-13 13:17:04 +03:00
template: '{{ "Hello World" | translate }}'
2019-06-13 12:59:36 +03:00
})
export class TestComponent { }
`;
const template = extractComponentInlineTemplate(contents);
2019-06-13 13:17:04 +03:00
expect(template).to.equal('{{ "Hello World" | translate }}');
2019-06-13 12:59:36 +03:00
});
it('should extract inline template spanning multiple lines', () => {
const contents = `
@Component({
selector: 'test',
template: '
<p>
Hello World
</p>
',
styles: ['
p {
color: red;
}
']
})
export class TestComponent { }
`;
const template = extractComponentInlineTemplate(contents);
expect(template).to.equal('\n\t\t\t\t\t<p>\n\t\t\t\t\t\tHello World\n\t\t\t\t\t</p>\n\t\t\t\t');
});
});