add test
parent
37047aef54
commit
a8348ca892
|
@ -0,0 +1,50 @@
|
|||
import { stopIE } from "../stop_ie";
|
||||
|
||||
describe("stopIE()", () => {
|
||||
beforeEach(() => {
|
||||
window.location.assign = jest.fn();
|
||||
window.alert = jest.fn();
|
||||
window.hasOwnProperty = () => true;
|
||||
Array.prototype.hasOwnProperty = () => true;
|
||||
Object.defineProperty(Object, "entries", {
|
||||
value: true, configurable: true
|
||||
});
|
||||
});
|
||||
|
||||
const expectToHaveBeenStopped = () => {
|
||||
expect(window.alert).toHaveBeenCalledWith(
|
||||
"This app only works with modern browsers.");
|
||||
expect(window.location.assign).toHaveBeenCalledWith(
|
||||
"https://www.google.com/chrome/");
|
||||
};
|
||||
|
||||
it("doesn't block when requirements are met", () => {
|
||||
stopIE();
|
||||
expect(window.alert).not.toHaveBeenCalled();
|
||||
expect(window.location.assign).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("blocks when requirements not met", () => {
|
||||
Object.defineProperty(Object, "entries", { value: undefined });
|
||||
stopIE();
|
||||
expectToHaveBeenStopped();
|
||||
});
|
||||
|
||||
it("blocks when requirements not met: window", () => {
|
||||
window.hasOwnProperty = () => false;
|
||||
stopIE();
|
||||
expectToHaveBeenStopped();
|
||||
});
|
||||
|
||||
it("blocks when requirements not met: array", () => {
|
||||
Array.prototype.hasOwnProperty = () => false;
|
||||
stopIE();
|
||||
expectToHaveBeenStopped();
|
||||
});
|
||||
|
||||
it("blocks when requirements not met: error", () => {
|
||||
Array.prototype.hasOwnProperty = () => { throw new Error(); };
|
||||
stopIE();
|
||||
expectToHaveBeenStopped();
|
||||
});
|
||||
});
|
|
@ -3,7 +3,7 @@ function flunk() {
|
|||
// IE Cannot handle it.
|
||||
const READ_THE_COMMENT_ABOVE = "This app only works with modern browsers.";
|
||||
alert(READ_THE_COMMENT_ABOVE);
|
||||
window.location.href = "https://www.google.com/chrome/";
|
||||
window.location.assign("https://www.google.com/chrome/");
|
||||
}
|
||||
|
||||
const REQUIRED_GLOBALS = [
|
||||
|
|
Loading…
Reference in New Issue