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:
@@ -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();
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user