🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@spetex
Copy link
Contributor

@spetex spetex commented May 25, 2020

In cases where the empty object is already set as default in the config:

See: stubs, mocks and methods
https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/config.js

The ? is not necessary. In this case, we can import the config and we will not be forced to check the existence of attributes:

import { config } from '@vue/test-utils';

if (config.mocks) {
  config.mocks.i18n = { t: jest.fn() };
  config.mocks.$t = jest.fn();
}

and use directly

import { config } from '@vue/test-utils';

config.mocks.i18n = { t: jest.fn() };
config.mocks.$t = jest.fn();

What kind of change does this PR introduce? (check at least one)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change? (check one)

  • Yes
  • No

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature (to avoid wasting your time, it's best to open a suggestion issue first and wait for approval before working on it)

Other information:

In cases where the empty object is already set as default in the config:

See: `stubs`, `mocks` and `methods`
https://github.com/vuejs/vue-test-utils/blob/dev/packages/test-utils/src/config.js

The ? is not necessary. In this case, we can import the config and we will not be forced to check the existence of attributes:

```
import { config } from '@vue/test-utils';

if (config.mocks) {
  config.mocks.i18n = { t: jest.fn() };
  config.mocks.$t = jest.fn();
}
```

and use directly

```
import { config } from '@vue/test-utils';

config.mocks.i18n = { t: jest.fn() };
config.mocks.$t = jest.fn();
```
Copy link
Member

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

I wish we could rewrite this in TS! Haha.

@lmiller1990 lmiller1990 merged commit a249065 into vuejs:dev May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants