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

68 lines
1.7 KiB
TypeScript
Raw 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',
template: 'Hello World'
})
export class TestComponent { }
`;
const template = extractComponentInlineTemplate(contents);
expect(template).to.equal('Hello World');
});
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');
});
});