Failure test case for getUserLang()

pull/639/head
Rick Carlino 2018-01-24 09:54:34 -06:00
parent 4a6e79a7af
commit 329f9bb7ee
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
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.
describe("getUserLang", () => {
it("defaults to `en` when failure occurs", (done) => {
getUserLang(LANG_CODE)
.then((result) => {
expect(axios.get).toHaveBeenCalled();
expect(axios.get).toHaveBeenCalledWith(generateUrl(LANG_CODE));
expect(result).toEqual("en");
done();
})
.catch((x) => {
fail(x.message);
});
});
});