(test) fix tests

This commit is contained in:
Kim Biesbjerg 2019-06-13 12:17:04 +02:00
parent 8493015e15
commit 3e43fde1cc
3 changed files with 22 additions and 16 deletions

View File

@ -107,7 +107,7 @@ describe('DirectiveParser', () => {
});
it('should not extract translate pipe in html tag', () => {
const contents = `<p>{{ 'Audiobooks for personal development' | translate }}</p>`;
const contents = `<p>{{ 'Audiobooks for personal development' | translate }}</p>`;
const collection = parser.extract(contents, templateFilename);
expect(collection.values).to.deep.equal({});
});
@ -124,10 +124,4 @@ describe('DirectiveParser', () => {
expect(keys).to.deep.equal(['Hello World']);
});
it('should not extract variables', () => {
const contents = '<p>{{ message | translate }}</p>';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([]);
});
});

View File

@ -43,13 +43,13 @@ describe('PipeParser', () => {
});
it('should extract interpolated strings using translate pipe in attributes', () => {
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
const contents = `<span attr="{{ 'Hello World' | translate }}"></span>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello World']);
});
it('should extract bound strings using translate pipe in attributes', () => {
const contents = `<span [attr]="'Hello World' | translate"></span>`;
const contents = `<span [attr]="'Hello World' | translate"></span>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello World']);
});
@ -58,14 +58,14 @@ describe('PipeParser', () => {
const contents = `
<ion-header>
<ion-navbar color="brand">
<ion-title>{{ 'Info' | translate }}</ion-title>
<ion-title>{{ 'Info' | translate }}</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<content-loading *ngIf="isLoading">
{{ 'Loading...' | translate }}
{{ 'Loading...' | translate }}
</content-loading>
</ion-content>
@ -75,7 +75,7 @@ describe('PipeParser', () => {
});
it('should extract strings on same line', () => {
const contents = `<span [attr]="'Hello' | translate"></span><span [attr]="'World' | translate"></span>`;
const contents = `<span [attr]="'Hello' | translate"></span><span [attr]="'World' | translate"></span>`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Hello', 'World']);
});
@ -85,7 +85,7 @@ describe('PipeParser', () => {
<ion-list inset>
<ion-item>
<ion-icon item-left name="person" color="dark"></ion-icon>
<ion-input formControlName="name" type="text" [placeholder]="'Name' | translate"></ion-input>
<ion-input formControlName="name" type="text" [placeholder]="'Name' | translate"></ion-input>
</ion-item>
<ion-item>
<p color="danger" danger *ngFor="let error of form.get('name').getError('remote')">
@ -94,11 +94,23 @@ describe('PipeParser', () => {
</ion-item>
</ion-list>
<div class="form-actions">
<button ion-button (click)="onSubmit()" color="secondary" block>{{ 'Create account' | translate }}</button>
<button ion-button (click)="onSubmit()" color="secondary" block>{{ 'Create account' | translate }}</button>
</div>
`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['Name', 'Create account']);
});
it('should not extract variables', () => {
const contents = '<p>{{ message | translate }}</p>';
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal([]);
});
it('should be able to extract without html', () => {
const contents = `{{ 'message' | translate }}`;
const keys = parser.extract(contents, templateFilename).keys();
expect(keys).to.deep.equal(['message']);
});
});

View File

@ -35,12 +35,12 @@ describe('Utils', () => {
const contents = `
@Component({
selector: 'test',
template: 'Hello World'
template: '{{ "Hello World" | translate }}'
})
export class TestComponent { }
`;
const template = extractComponentInlineTemplate(contents);
expect(template).to.equal('Hello World');
expect(template).to.equal('{{ "Hello World" | translate }}');
});
it('should extract inline template spanning multiple lines', () => {