Test Files paths in Angular2

0

I want to do a check in Angular2, which consists of verifying that said file is there and that it has not been deleted accidentally.

The problem is that I realize that I am comparing the strings, not the file itself.

it('I check routes i18n', () => {
const  i18nEs = "../../../server/i18n/es.json";
const i18nIng = "../../../server/i18n/en.json"

expect(i18nEs).toBe("../../../server/i18n/es.json");
expect(i18nIng).toBe("../../../server/i18n/en.json");

  });
    
asked by EduBw 27.04.2018 в 08:31
source

1 answer

1

You can prepare a service that makes a HEAD request to your local resource:

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import 'rxjs/add/operator/mapTo';
import 'rxjs/add/operator/toPromise';

getFileStatus(path: string): Promise<boolean> {
    return this.http.head(path)
        .mapTo(true)
        .catch((error) => Observable.of(false))
        .toPromise();
}

Source

    
answered by 27.04.2018 / 09:50
source