vue test utils test

해피데빙·2023년 3월 21일
0

event trigger

TouchEvent, CustomEvent

TouchEvent

CustomEvent

This error is occurring because the TouchEvent object in your test is missing the isTrusted property. The isTrusted property is a read-only property that is set by the browser and cannot be modified in a script.

To resolve this error, you can use a CustomEvent instead of a TouchEvent to simulate a touch event. Here's an example of how you can modify your code to use a CustomEvent:

javascript

jest 문법

matcher

expect.objectContaining(object)

matches any received object that recursively matches the expected properties. That is, the expected object is a subset of the received object. Therefore, it matches a received object which contains properties that are present in the expected object.

Instead of literal property values in the expected object, you can use matchers, expect.anything(), and so on.

test('onPress gets called with the right thing', () => {
  const onPress = jest.fn();
  simulatePresses(onPress);
  expect(onPress).toHaveBeenCalledWith(
    expect.objectContaining({
      x: expect.any(Number),
      y: expect.any(Number),
    }),
  );
});

Vue router

router

testing router hooks

문제

  • express를 이용해 ssr
  • 탭에서만 vue router 사용
  • 컴포넌트에서 beforeEach를 이용해 '#'만 붙임
  • 이걸 확인을 안해서 coverage가 떨어짐
  • mock router를 만들거나 실제 router를 사용
  • 실제 router를 사용할 거면 local
profile
노션 : https://garrulous-gander-3f2.notion.site/c488d337791c4c4cb6d93cb9fcc26f17

0개의 댓글