Skip to content

Improve types for mocks and provide in config options #875

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 29, 2018
Merged

Improve types for mocks and provide in config options #875

merged 8 commits into from
Jul 29, 2018

Conversation

cesalberca
Copy link
Contributor

This PR allows users of TypeScript to use bracket notation without the need to cast to any.

Before:

;(config.mocks as any)['foo'] = {
  bar: 'baz'
}

After:

config.mocks['foo'] = {
  bar: 'baz'
}

Also, continuing work from this PR: #874, I set allowSyntheticDefaultImports to true in order to import default export without errors.

@eddyerburgh
Copy link
Member

Is this PR complete?

@cesalberca
Copy link
Contributor Author

Yes it is! However I'm still confused about the signaturee of methods: https://vue-test-utils.vuejs.org/api/#config. Is config.methods an object that receives a function that returns an object? Or an object that receives a function that declares some functions?

@eddyerburgh
Copy link
Member

No, it's an object that's merged into component instance methods. The example is confusing, can you please replace it with this:

config.methods['getData'] = () => {}

@cesalberca
Copy link
Contributor Author

If it's an object then the docs are not correct as:

config.methods['errors'] = () => {
  any: () => false
}

Is equivalent to:

config.methods['errors'] = function() {
 // This is a labeled statement inside the function, not an object
 any: () => false
}

If we wanted an object the docs should be as follows:

config.methods['errors'] = () => ({
  any: () => false
})

Note the parenthesis.

@eddyerburgh
Copy link
Member

Yes that's why I asked if you could replace the example. As you said, it's incorrect.

@cesalberca
Copy link
Contributor Author

Aaah, alright then! I'll change it then

@eddyerburgh
Copy link
Member

Can you fix the linting error please?

https://circleci.com/gh/vuejs/vue-test-utils/7489?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

@cesalberca
Copy link
Contributor Author

Done, ready to merge!

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

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

Great work, thanks :)

@eddyerburgh eddyerburgh merged commit 3afafdd into vuejs:dev Jul 29, 2018
@cesalberca cesalberca deleted the feature/improve-types branch July 29, 2018 19:19
kuitos pushed a commit to kuitos/vue-test-utils that referenced this pull request Aug 2, 2018
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