Farmbot-Web-App/frontend/__tests__/i18next_failure_tests.ts

32 lines
766 B
TypeScript
Raw Normal View History

2018-01-24 08:54:34 -07:00
jest.mock("axios", () => {
return {
default: {
get: jest.fn((_url: string) => {
return Promise.reject("Simulated failure");
})
}
};
});
import { generateUrl, getUserLang } from "../i18n";
import axios from "axios";
const LANG_CODE = "ab_CD"; // Intentionally non-existent lang code.
2018-05-15 20:38:52 -06:00
const HOST = "";
const PORT = "";
2018-01-24 08:54:34 -07:00
describe("getUserLang", () => {
it("defaults to `en` when failure occurs", (done) => {
2018-05-15 20:38:52 -06:00
getUserLang(LANG_CODE, HOST, PORT)
2018-01-24 08:54:34 -07:00
.then((result) => {
expect(axios.get).toHaveBeenCalled();
2018-05-15 20:38:52 -06:00
expect(axios.get).toHaveBeenCalledWith(generateUrl(LANG_CODE, HOST, PORT));
2018-01-24 08:54:34 -07:00
expect(result).toEqual("en");
done();
})
.catch((x) => {
fail(x.message);
});
});
});