Created
July 9, 2022 11:44
-
-
Save danywalls/49dc74db93aa9fb1402a486152f56de2 to your computer and use it in GitHub Desktop.
ngx translate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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