{"size": 1956, "ext": "js", "max_stars_repo_path": "test/specs/expect/instance/to-have-props.spec.js", "max_stars_repo_name": "cibernox/svelte-mock", "max_stars_repo_stars_event_min_datetime": "2019-09-28T18:55:48.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-27T15:36:32.000Z", "max_issues_repo_path": "test/specs/expect/instance/to-have-props.spec.js", "max_issues_repo_name": "cibernox/svelte-mock", "max_issues_repo_issues_event_min_datetime": "2022-02-17T20:36:25.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-18T15:45:06.000Z", "max_forks_repo_path": "test/specs/expect/instance/to-have-props.spec.js", "max_forks_repo_name": "cibernox/svelte-mock", "max_forks_repo_forks_event_min_datetime": "2022-02-17T20:36:34.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-17T20:36:34.000Z"}
{"max_stars_count": 13, "max_issues_count": 2, "max_forks_count": 1, "avg_line_length": 30.5625, "max_line_length": 79, "alphanum_fraction": 0.6283231084}
import { requireMockFixture, tick } from '@test/utils';
import { SVELTE_CHANGES } from '@test/utils/version';

const Fullname = requireMockFixture('Fullname.svelte');
svelteMock.mockImplementation(Fullname);

beforeEach(() => {
  jest.clearAllMocks();
});

describe('expect(component).toHaveProps(props)', () => {
  it('should pass if props match', () => {
    // Given
    const target = document.createElement('div');
    const props = { firstname: 'Rick', lastname: 'Flaherty' };
    // When
    const component = new Fullname({
      target, [SVELTE_CHANGES.OPTION_PROPS]: props,
    });
    // Then
    expect(component).toHaveProps({ firstname: 'Rick', lastname: 'Flaherty' });
  });

  it('should pass if props match a subset of the component\'s props', () => {
    // Given
    const target = document.createElement('div');
    const props = { firstname: 'Jean', lastname: 'Flaherty' };
    // When
    const component = new Fullname({
      target, [SVELTE_CHANGES.OPTION_PROPS]: props,
    });
    // Then
    expect(component).toHaveProps({ firstname: 'Jean' });
  });

  it('should pass if props match after state updates', async () => {
    // Given
    const target = document.createElement('div');
    const props = { firstname: 'Jean', lastname: 'Flaherty' };
    const component = new Fullname({
      target, [SVELTE_CHANGES.OPTION_PROPS]: props,
    });
    // When
    component[SVELTE_CHANGES.SET_METHOD]({ firstname: 'Sachico' });
    await tick();
    // Then
    expect(component).toHaveProps({
      firstname: 'Sachico', lastname: 'Flaherty',
    });
  });

  it('should fail if props do not match', () => {
    // Given
    const target = document.createElement('div');
    const props = { firstname: 'Jean', lastname: 'Flaherty' };
    // When
    const component = new Fullname({
      target, [SVELTE_CHANGES.OPTION_PROPS]: props,
    });
    // Then
    expect(component).not.toHaveProps({ lastname: 'Furuhata' });
  });
});
