1
0
mirror of https://github.com/bitwarden/jslib synced 2025-12-11 05:43:18 +00:00

Migrate components to use jest (#793)

* Migrate components to use jest (tests fail)

* Fix failing tests

* Fix linting errors
This commit is contained in:
Oscar Hinton
2022-05-12 17:33:49 +02:00
committed by GitHub
parent 1370006f6e
commit de2eb0359b
11 changed files with 10867 additions and 240 deletions

View File

@@ -17,7 +17,7 @@ describe("BannerComponent", () => {
});
it("should create with alert", () => {
expect(component.useAlertRole).toBeTrue();
expect(component.useAlertRole).toBe(true);
const el = fixture.nativeElement.children[0];
expect(el.getAttribute("role")).toEqual("status");
expect(el.getAttribute("aria-live")).toEqual("polite");
@@ -27,7 +27,7 @@ describe("BannerComponent", () => {
component.useAlertRole = false;
fixture.autoDetectChanges();
expect(component.useAlertRole).toBeFalse();
expect(component.useAlertRole).toBe(false);
const el = fixture.nativeElement.children[0];
expect(el.getAttribute("role")).toBeNull();
expect(el.getAttribute("aria-live")).toBeNull();

View File

@@ -1,8 +1,9 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { I18nMockService } from "src/utils/i18n-mock.service";
import { I18nService } from "jslib-common/abstractions/i18n.service";
import { I18nMockService } from "../utils/i18n-mock.service";
import { CalloutComponent } from ".";
describe("Callout", () => {

View File

@@ -14,7 +14,7 @@ describe("Menu", () => {
};
// The overlay is created outside the root debugElement, so we need to query its parent
const getBitMenuPanel = () => fixture.debugElement.parent.query(By.css(".bit-menu-panel"));
const getBitMenuPanel = () => document.querySelector(".bit-menu-panel");
beforeEach(
waitForAsync(() => {
@@ -30,7 +30,7 @@ describe("Menu", () => {
})
);
it("should open when the trigger is clicked", () => {
it("should open when the trigger is clicked", async () => {
const buttonDebugElement = fixture.debugElement.query(By.directive(MenuTriggerForDirective));
(buttonDebugElement.nativeElement as HTMLButtonElement).click();
@@ -49,7 +49,7 @@ describe("Menu", () => {
it("should close when a menu item is clicked", () => {
getMenuTriggerDirective().toggleMenu();
fixture.debugElement.parent.query(By.css("#item1")).nativeElement.click();
(document.querySelector("#item1") as HTMLAnchorElement).click();
expect(getBitMenuPanel()).toBeFalsy();
});
@@ -57,7 +57,7 @@ describe("Menu", () => {
it("should close when the backdrop is clicked", () => {
getMenuTriggerDirective().toggleMenu();
fixture.debugElement.parent.query(By.css(".cdk-overlay-backdrop")).nativeElement.click();
(document.querySelector(".cdk-overlay-backdrop") as HTMLAnchorElement).click();
expect(getBitMenuPanel()).toBeFalsy();
});