私は実際のサービスで機能を使用していますが、ユニットテストケースでその機能をどのように注入できるかを知りたいと思います。以下はisDameDayはプロバイダではない関数です。この関数は実際のサービスでうまく動作しているので、どのようにテストケースに挿入できますか? isSameDay機能についてファンクションプロバイダを使用しない角2ユニットテストケース
import { LoggerService, isSameDay } from '../../../shared';
describe('NavBaseComponent',() => {
let component: NavBaseComponent;
let fixture: ComponentFixture<NavBaseComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [NavBaseComponent],
providers: [
LoggerService
]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(NavBaseComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should be created',() => {
expect(component).toBeTruthy();
});
});
コードが
export function isSameDay(d1: Date, d2: Date): boolean {
return !!d1 && !!d2 &&
d1.getDate() === d2.getDate() &&
d1.getMonth() === d2.getMonth() &&
d1.getFullYear() === d2.getFullYear();
};
共有コードを追加できますか?それはプロバイダの中のメソッドなのでしょうか? – echonax
多くの場所で使用されている機能です – Rohit