vendredi 3 août 2018

Testing Angular class

I'm trying to test my class which has one depedency(service). There is problem with undefined method. I have run off idea i tried to use stubs and everthing but there is still undefined. Get configuration method undefined

test

let fakeData: HiddenColumn = {
    columnNames: "id,name,code",
    id: 1,
    modelType: 10
};

export class HiddenColumnServiceStub {
    constructor() { }
    public getConfiguration(modelType: ObjectEnumType): Observable<HiddenColumn> {
        return of(fakeData);
    }
}

describe('#Grid base', () => {
    let service: HiddenColumnService;
    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [
                HttpClientTestingModule
            ],
            providers: [
                { provide: HiddenColumnService, useClass: HiddenColumnServiceStub }
            ]
        });
        service = TestBed.get(HiddenColumnService);
    }));
    let gridBase = new GridBase(service);
    gridBase.objectType = ObjectEnumType.Storehouse;
    it('service defined', () => {
        expect(service).toBeDefined();
    });
    it('gridBase defined', () => {
        expect(gridBase).toBeDefined();
    });
    it('should do something', async(() => {
        gridBase.getConfigurationOfColumns();
        expect(gridBase.hiddenColumns = ['id', 'name', 'code', '2']);
    }));
});

}

Aucun commentaire:

Enregistrer un commentaire