Add tests, remove carriage returns.

pull/1253/head
Rick Carlino 2019-06-27 09:26:01 -05:00
parent dea4db156b
commit cca51135fb
2 changed files with 38 additions and 3 deletions

View File

@ -1,5 +1,39 @@
const mockRun = jest.fn();
class MockFBToast {
static everyMessage: Record<string, boolean> = {};
run = mockRun;
}
jest.mock("../fb_toast", () => {
return { FBToast: MockFBToast };
});
import { FBToast } from "../fb_toast";
import { createToastOnce, createToast } from "../toast_internal_support";
describe("toast internal support files", () => {
it("creates a toast and attaches to DOM", () => {
const msg = "foo";
const fallback = jest.fn();
const container = document.createElement("DIV");
container.className = "toast-container";
document.body.appendChild(container);
createToastOnce(msg, "bar", "baz", fallback);
expect(FBToast.everyMessage[msg]).toBe(true);
expect(fallback).not.toHaveBeenCalled();
expect(mockRun).toHaveBeenCalled();
createToastOnce(msg, "bar", "baz", fallback);
expect(fallback).toHaveBeenCalled();
});
it("crashes if you don't attach .toast-container", () => {
document.body.innerHTML = "";
expect(() => createToast("x", "y", "z"))
.toThrow();
});
});

View File

@ -23,15 +23,17 @@ export class FBToast {
/** Declare if the user's mouse is hovering over the message. */
public isHovered = false;
public message = "";
constructor(public parent: Element,
title: string,
public message: string,
raw_message: string,
color: string) {
this.message = raw_message.replace(/\s+/g, " ");
/** Fill contents. */
this.titleEl.innerText = title;
this.messageEl.innerText = message;
this.messageEl.innerText = this.message;
/** Add classes. */
this.toastEl.classList.add("toast");
@ -105,7 +107,6 @@ export class FBToast {
};
run = () => {
/** Append children. */
this.parent.appendChild(this.toastEl);
// TSC Thinks this is a node project :-\