第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

類型錯誤:無法在“URL”上執(zhí)行“createObjectURL”:找不到與提供的簽名匹配的函數(shù)

類型錯誤:無法在“URL”上執(zhí)行“createObjectURL”:找不到與提供的簽名匹配的函數(shù)

滄海一幻覺 2023-03-03 10:40:08
我有一個 angular 8 應(yīng)用程序,我用 jasmine karma 做了一些單元測試。所以這是 component.ts:export class DossierPersonalDataComponent implements OnInit {  dossier: DossierDto;  editDossierForm: FormGroup;  formBuilder = new FormBuilder();  globalEditDossierErrors: ValidationErrors;  dossierItems: DossierItemDto[] = [];  profileImagefile: File;  profileImageNeedsUpload = false;  constructor(    private dossierService: DossierService,    private route: ActivatedRoute,    private sanitizer: DomSanitizer,    private dossierFileService: DossierFileService,    private errorProcessor: ErrorProcessor,    private dialog: MatDialog  ) {    this.dossierItems = this.route.snapshot.data.dossierItems;    this.editDossierForm = this.formBuilder.group({});    this.editDossierForm.disable();    this.dossier = this.route.snapshot.data.dossier;    this.dossierItems = route.snapshot.data.dossierItems;    this.profileImagefile = this.route.snapshot.data.profileImage;    this.editDossierForm = this.formBuilder.group({      firstName: this.formBuilder.control(this.dossier.firstName, [Validators.required, Validators.maxLength(255)]),      lastName: this.formBuilder.control(this.dossier.lastName, [Validators.required, Validators.maxLength(255)]),      mobile: this.formBuilder.control(this.dossier.mobile, [Validators.maxLength(255)]),      company: this.formBuilder.control(this.dossier.company, [Validators.maxLength(255)]),      buddy: this.formBuilder.control(this.dossier.buddy, [Validators.maxLength(255)]),      supervisor: this.formBuilder.control(this.dossier.supervisor, [Validators.maxLength(255)]),      dateOfBirth: this.formBuilder.control(this.dossier.dateOfBirth)    });  }  ngOnInit(): void {    this.editDossierForm.disable();  }  editName() {    this.editDossierForm.enable();  }  get profileImageUrl() {    return this.profileImagefile === null      ? '/assets/placeholder.jpg'      : this.sanitizer.bypassSecurityTrustUrl(window.URL.createObjectURL(this.profileImagefile));  }}
查看完整描述

1 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個贊

似乎 karma chrome 不支持 deprecated createObjectURL。以下是讓它與業(yè)力一起工作的方法:


export class DossierPersonalDataComponent implements OnInit {

  dossier: DossierDto;

  editDossierForm: FormGroup;

  formBuilder = new FormBuilder();

  globalEditDossierErrors: ValidationErrors;

  dossierItems: DossierItemDto[] = [];

  profileImagefile: File;

  profileImageNeedsUpload = false;

  compWindow: any;


  constructor(

    private dossierService: DossierService,

    private route: ActivatedRoute,

    private sanitizer: DomSanitizer,

    private dossierFileService: DossierFileService,

    private errorProcessor: ErrorProcessor,

    private dialog: MatDialog

  ) {

    // this would help you to mock the "window" object in spec file

    this.compWindow = window;

    // please move below code to ngOnInit as standard practice of Angular.


    this.dossierItems = this.route.snapshot.data.dossierItems;

    this.editDossierForm = this.formBuilder.group({});

    this.editDossierForm.disable();


    this.dossier = this.route.snapshot.data.dossier;

    this.dossierItems = route.snapshot.data.dossierItems;

    this.profileImagefile = this.route.snapshot.data.profileImage;


    this.editDossierForm = this.formBuilder.group({

      firstName: this.formBuilder.control(this.dossier.firstName, [Validators.required, Validators.maxLength(255)]),

      lastName: this.formBuilder.control(this.dossier.lastName, [Validators.required, Validators.maxLength(255)]),

      mobile: this.formBuilder.control(this.dossier.mobile, [Validators.maxLength(255)]),

      company: this.formBuilder.control(this.dossier.company, [Validators.maxLength(255)]),

      buddy: this.formBuilder.control(this.dossier.buddy, [Validators.maxLength(255)]),

      supervisor: this.formBuilder.control(this.dossier.supervisor, [Validators.maxLength(255)]),

      dateOfBirth: this.formBuilder.control(this.dossier.dateOfBirth)

    });

  }

  ngOnInit(): void {

    this.editDossierForm.disable();

  }


  editName() {

    this.editDossierForm.enable();

  }


  get profileImageUrl() {

    return this.profileImagefile === null

      ? '/assets/placeholder.jpg'

      : this.sanitizer.bypassSecurityTrustUrl(this.compWindow.URL.createObjectURL(this.profileImagefile));

  }

}

在spec.ts文件中:


describe('DossierPersonalDataComponent', () => {

  let component: DossierPersonalDataComponent;

  let fixture: ComponentFixture<DossierPersonalDataComponent>;

  const myWindow = {

    URL : {

      createObjectURL() { return 'something'; }

    }

  };


  beforeEach(async(() => {

    TestBed.configureTestingModule({

      imports: [HttpClientTestingModule, DossierModule, BrowserModule],

      declarations: [DossierPersonalDataComponent],

      providers: [

          DossierFileService,

          ErrorProcessor,

          {

            provide: ActivatedRoute,

            useValue: {

              snapshot: {

                data: {

                  dossier: {

                    firstName: 'hello',

                    lastName: 'world',

                    mobile: '111-111-1111',

                    company: 'carapax',

                    buddy: 'bud',

                    supervisor: 'super',

                    dateOfBirth: '1900-01-01',

                  },

                  dossierItems: [], // mock

                  profileImage: '',

                }

              }

            }

          },

        {

          provide: DomSanitizer,

          useValue: {

            sanitize: () => 'safeString',

            bypassSecurityTrustHtml: () => 'safeString'

          }

        }

      ]

    })

      .compileComponents()

      .then(() => {

        fixture = TestBed.createComponent(DossierPersonalDataComponent);

        component = fixture.componentInstance;

        component.compWindow =  myWindow; // this would override the value we are setting in constructor. 

        fixture.detectChanges(); // once we have overridden it, now call "detectChanges"

      });

  }));



  it('should create', () => {

    expect(component).toBeTruthy();

  }); 

});



查看完整回答
反對 回復(fù) 2023-03-03
  • 1 回答
  • 0 關(guān)注
  • 278 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號