Angular12 控制台仅从 main.js:1 和 polyfills.js:1 记录

问题描述 投票:0回答:1

我正在构建一个新的角度应用程序,在我执行 console.log 的任何地方,它都来自 main.js:1 或 polyfills.js:1 而不是来自正确的组件。

"localdev": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment-localdev.ts"
}
]

"dependencies": {
"@angular/animations": "~12.1.0-",
"@angular/cdk": "^12.1.3",
"@angular/common": "~12.1.0-",
"@angular/compiler": "~12.1.0-",
"@angular/core": "~12.1.0-",
"@angular/forms": "~12.1.0-",
}
angular angular-cli
1个回答
0
投票
    import { async, ComponentFixture, TestBed } from '@angular/core/testing';
    import { MatDialogModule } from '@angular/material/dialog';
    import { RouterTestingModule } from '@angular/router/testing';
    import { HttpClientTestingModule } from '@angular/common/http/testing';
    import { TruCoreModule } from '@truist/tru-core';
    import { SetupNotificationsComponent } from './setup-notifications.component';
    
    describe('SetupNotificationsComponent', () => {
      let component: SetupNotificationsComponent;
      let fixture: ComponentFixture<SetupNotificationsComponent>;
    
      beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [SetupNotificationsComponent],
          imports: [
            MatDialogModule,
            RouterTestingModule,
            HttpClientTestingModule,
            TruCoreModule
          ]
        }).compileComponents();
      }));
    
      beforeEach(() => {
        fixture = TestBed.createComponent(SetupNotificationsComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
      });
    
      it('should create the component', () => {
        expect(component).toBeTruthy();
      });
    
      it('should initialize component properties correctly', () => {
        // Add your initialization expectations here
      });
    
      it('should redirect to setup notification', () => {
        spyOn(component.router, 'navigate');
        component.redirectToSetupNotification();
        expect(component.router.navigate).toHaveBeenCalledWith(['/tools/setupNotification']);
      });
    
      it('should navigate for breadcrumb navigation', () => {
        spyOn(component.router, 'navigate');
        component.breadCrumbNav();
        expect(component.router.navigate).toHaveBeenCalledWith(['/tools/manageNotification']);
      });
    
      it('should handle notification saved', () => {
        spyOn(component, 'displaySnackBar');
        component.onSaved();
        expect(component.displaySnackBar).toHaveBeenCalledWith('Your notification has been saved', 'success');
      });
    
      it('should handle notification save error', () => {
        spyOn(component, 'displaySnackBar');
        component.onSaveError();
        expect(component.displaySnackBar).toHaveBeenCalledWith('Error saving notification', 'error');
      });
    
      it('should emit step1Continue event', () => {
        const mockEvent = {};
        component.onEmitStep1Contine(mockEvent);
        expect(component.notificationDetails).toEqual(mockEvent);
        expect(component.step1ViewMode).toBe('view');
        expect(component.isStep2Enabled).toBe(true);
        expect(component.step2ViewMode).toBe('add');
      });
    
      it('should handle step1Continue event with empty notificationDetails', () => {
        const mockEvent = {};
        component.notificationDetails = {};
        component.onEmitStep1Contine(mockEvent);
        expect(component.notificationDetails).toEqual(mockEvent);
        expect(component.step1ViewMode).toBe('view');
        expect(component.isStep2Enabled).toBe(true);
        expect(component.step2ViewMode).toBe('add');
      });
    
      it('should emit step2Continue event', () => {
        const mockEvent = {};
        component.onEmitStep2Contine(mockEvent);
        expect(component.accountDetails).toEqual(mockEvent);
        expect(component.isStep3Enabled).toBe(true);
        expect(component.step3ViewMode).toBe('add');
      });
    
      it('should handle step2Continue event with empty accountDetails', () => {
        const mockEvent = {};
        component.accountDetails = {};
        component.onEmitStep2Contine(mockEvent);
        expect(component.accountDetails).toEqual(mockEvent);
        expect(component.isStep3Enabled).toBe(true);
        expect(component.step3ViewMode).toBe('add');
      });
    
      it('should emit step3Continue event', () => {
        const mockEvent = {};
        component.onEmitStep3Contine(mockEvent);
        expect(component.recipientsDetails).toEqual(mockEvent);
        expect(component.step3Invalid).toBe(false);
        expect(component.step3ViewMode).toBe('edit');
        expect(component.isNotificationSaveEnabled).toBe(true);
        expect(component.step1ViewMode).toBe('edit');
        expect(component.step2ViewMode).toBe('edit');
      });
    
      it('should handle step3Continue event with empty recipientsDetails', () => {
        const mockEvent = {};
        component.recipientsDetails = {};
        component.onEmitStep3Contine(mockEvent);
        expect(component.recipientsDetails).toEqual(mockEvent);
        expect(component.step3Invalid).toBe(false);
        expect(component.step3ViewMode).toBe('edit');
        expect(component.isNotificationSaveEnabled).toBe(true);
        expect(component.step1ViewMode).toBe('edit');
        expect(component.step2ViewMode).toBe('edit');
      });
    
      it('should handle onEdit with step1 event', () => {
        component.onEdit('step1');
        expect(component.isNotificationSaveEnabled).toBe(false);
        expect(component.isStep2Enabled).toBe(false);
        expect(component.isStep3Enabled).toBe(false);
        expect(component.step1ViewMode).toBe('add');
        expect(component.step2ViewMode).toBe('view');
        expect(component.step3ViewMode).toBe('view');
      });
    
      it('should handle onEdit with step2 event', () => {
        component.onEdit('step2');
        expect(component.isNotificationSaveEnabled).toBe(false);
        expect(component.isStep2Enabled).toBe(true);
        expect(component.isStep3Enabled).toBe(false);
        expect(component.step1ViewMode).toBe('view');
        expect(component.step2ViewMode).toBe('add');
        expect(component.step3ViewMode).toBe('view');
      });
    
      it('should handle onEdit with step3 event', () => {
        component.onEdit('step3');
        expect(component.isNotificationSaveEnabled).toBe(false);
        expect(component.isStep2Enabled).toBe(false);
        expect(component.isStep3Enabled).toBe(true);
        expect(component.step1ViewMode).toBe('view');
        expect(component.step2ViewMode).toBe('view');
        expect(component.step3ViewMode).toBe('add');
      });
    
      it('should navigate to manage notification', () => {
        spyOn(component.router, 'navigate');
        component.goToManageNotification();
        expect(component.router.navigate).toHaveBeenCalledWith(['/tools/manageNotification']);
      });
    
      // Add more test cases as

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { TruCoreModule } from '@truist/tru-core';
import { NotificationsDetailsComponent } from './notifications-details.component';

describe('NotificationsDetailsComponent', () => {
  let component: NotificationsDetailsComponent;
  let fixture: ComponentFixture<NotificationsDetailsComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [NotificationsDetailsComponent],
      imports: [
        MatDialogModule,
        RouterTestingModule,
        HttpClientTestingModule,
        TruCoreModule
      ]
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(NotificationsDetailsComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create the component', () => {
    expect(component).toBeTruthy();
  });

  it('should initialize component properties correctly', () => {
    expect(component.notificationsFilter).toBe('');
    expect(component.notificationsTableColumns).toBeTruthy();
    expect(component.notificationsTableRows).toBeTruthy();
    // Add more initialization expectations
  });

  it('should transform notificationTypeList', () => {
    const mockNotificationTypeList = [
      // Mock notification type list
    ];
    component.notificationTypeList = mockNotificationTypeList;
    component.transformNotificationTypeList();

    expect(component.notificationsTableRows.length).toBe(mockNotificationTypeList.length);
    // Add more expectations for the transformed notificationTypeList
  });

  it('should set notificationsTableRows based on filter', () => {
    const mockNotificationTypeList = [
      // Mock notification type list
    ];
    component.notificationTypeList = mockNotificationTypeList;
    component.transformNotificationTypeList();

    component.transformNotificationTypeList('PavementReceived');
    // Add expectations for filtered notificationsTableRows

    component.transformNotificationTypeList('');
    // Add expectations for notificationsTableRows without filtering
  });

  it('should select a notification and update related data', () => {
    const mockNotificationTypeList = [
      // Mock notification type list
    ];
    component.notificationTypeList = mockNotificationTypeList;
    component.transformNotificationTypeList();

    const mockSelectedNotification = mockNotificationTypeList[0];
    component.selectedNotification = mockSelectedNotification.notificationTypeld;
    component.onSelectNotification(mockSelectedNotification);

    expect(component.notificationsTableRows[0].content.status.selected).toBe(true);
    // Add more expectations for updated notificationsTableRows and related data
  });

  it('should emit step1Continue event', () => {
    const mockNotificationDetails = {
      notificationTypeld: 10,
      notificationName: 'Test Notification',
      notifyAmountOption: 'Test Option',
      selectedNotification: 10,
      notificationAmount: 100,
      notifyamountOptions: [
        // Mock options
      ]
    };
    spyOn(component.onStep1Contine, 'next');
    component.onContinuel();
    expect(component.onStep1Contine.next).toHaveBeenCalledWith(mockNotificationDetails);
  });

  it('should handle onEdit event', () => {
    spyOn(component.onEditNotificationDetails, 'next');
    component.onEdit();
    expect(component.onEditNotificationDetails.next).toHaveBeenCalledWith('step1');
  });

  it('should handle onCancel event', () => {
    spyOn(component.notificationsTableRows[0].content.status, 'toggle');
    component.onCancel();
    expect(component.notificationsTableRows[0].content.status.toggle).toHaveBeenCalledWith(false);
  });

  it('should handle onCancel event and clear input fields', () => {
    component.notificationNickname = 'Test';
    component.notifyAmountOption = 'Option';
    component.notificationAmount = 'Amount';
    component.onCancel();
    expect(component.notificationNickname).toBe('');
    expect(component.notifyAmountOption).toBe('');
    expect(component.notificationAmount).toBe('');
  });

  // Add more test cases for other methods and functions

});
© www.soinside.com 2019 - 2024. All rights reserved.