lundi 20 mai 2019

Issues with show dialog testing - how to get object with styles in tests

I getting two errors at this moment. The first one is like this:

Expected Object({ width: '10%' }) to match /{width: 10% }/.

Or something like that:

Expected Object({ width: '10%' }) to match '{width: 10% }'.

I understand why i getting this, but i didn't have idea how to test it in other way - i can put there only string or RegExp. Tere is sample of code which wanna test:

public showSettingDialog() {
    this.dialogService.open(SettingsComponent, {
      width: '55%',
      contentStyle: { 'max-height': '700px' }
    });

And my attempt to test it (only difference is changing '' to // in arg2.toMatch):

it('should show setting dialog', () => {
    spyOn(SUT.dialogService, 'open').and.callFake(function(arg1, arg2) {
      expect(arg1).toMatch(/SettingsComponent/);
      expect(arg2).toMatch('{width: 10% }');
    });
    SUT.dialogService.open(SettingsComponent, {width: '10%'});
    expect(SUT.dialogService).toHaveBeenCalled();
  });

Aucun commentaire:

Enregistrer un commentaire