Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save danywalls/49dc74db93aa9fb1402a486152f56de2 to your computer and use it in GitHub Desktop.
Save danywalls/49dc74db93aa9fb1402a486152f56de2 to your computer and use it in GitHub Desktop.
ngx translate
import { AppComponent } from './app.component';
import { Pipe, PipeTransform } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateService } from '@ngx-translate/core';
@Pipe({ name: 'translate' })
class MockPipe implements PipeTransform {
transform(value: string): string {
return '';
}
}
describe('AppComponent', () => {
let translateServiceMock: any;
let component: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(() => {
translateServiceMock = jasmine.createSpyObj('TranslateService', ['setDefaultLang', 'use']);
TestBed.configureTestingModule({
declarations: [AppComponent, MockPipe],
providers: [{ provide: TranslateService, useValue: translateServiceMock }]
}).compileComponents();
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
});
it('can load instance', () => {
expect(component).toBeTruthy();
});
it('should call TranslateService.setDefaultLang()', () => {
expect(translateServiceMock.setDefaultLang).toHaveBeenCalled();
});
it('should call TranslateService.use()', () => {
expect(translateServiceMock.use).toHaveBeenCalled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment