Skip to content
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

docs: update docs (fix #873) #874

Merged
merged 7 commits into from Jul 29, 2018
Merged

docs: update docs (fix #873) #874

merged 7 commits into from Jul 29, 2018

Conversation

cesalberca
Copy link
Contributor

With version 1.0.0-beta.20 the default export has been removed. This PR updates all the documentation that imports the default export and changes it accordingly.

I also took the liberty of replacing the bracket notation documentation to set global configuration to object notation. The reasoning is the following:

  1. Object notation is easier to understand for begginners.
  2. Object notation easily extensible. If I want to add two properties I can do as follows:
config.mocks = {
  foo: {
    bar: () => true
  },
  baz: {
    qux: () => true
  }
}

While with bracket notation I would have to something like this:

config.mocks['foo'] = bar = () => true
config.mocks['baz'] = qux = () => true
  1. Using Object notation does not error in TypeScript while bracket notation does:

image

You would have to cast to any to make use of it:
image

This will make TypeScript users have a seamless experience.

Another thing to have into consideration is the change made to the methods config option.

The previous documentation states that global config methods should be declared as follows:

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

However, this is equivalent to this:

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

Which I think it should be like this:

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

Note that when using arrow functions, if we want an implicit return of an object we have to wrap it around parentheses:

const foo = () => ({ bar: 42 })

Which is the correct version then? I assumed errors must be an object, but I could be wrong.

@cesalberca cesalberca changed the title docs: update docs fix #873 docs: update docs (fix #873) Jul 29, 2018
@eddyerburgh
Copy link
Member

Thanks for the PR, I'll read through it now. However, I'm confused about why you think Vue Test Utils removed default export in beta.20. The dist file has exported the same object for the last three months—https://github.com/vuejs/vue-test-utils/blame/dev/packages/test-utils/dist/vue-test-utils.js#L5563

@eddyerburgh
Copy link
Member

Also I disagree about changing from bracket notation in the config. The examples now overwrite the previous object, whereas bracket notation would only overwrite a property if it existed.

@cesalberca
Copy link
Contributor Author

cesalberca commented Jul 29, 2018

I created a new project using Vue CLI 3.0 (with vue-test-utils 1.0.0-beta.21) and this error appears:

image

It's weird since in another project of mine I don't have any errors importing VueTestUtils, and in that project I have 1.0.0-beta.19. I tried downgrading in this project (https://github.com/cesalberca/i18n-typescript-tests-bug) to that version but I still have that error.

Regarding the notation: given that they are global mocks, shouldn't they be overwritten only once?

@eddyerburgh
Copy link
Member

Ah that's an issue with the types, are you able to fix it in this PR?

Regarding the notation: given that they are global mocks, shouldn't they be overwritten only once?

Not necessarily. For example, stubs contains default stubs for Transition, TranstionGroup, and RouterLink, so overriding would remove those stubs.

@eddyerburgh eddyerburgh merged commit d5fceb7 into vuejs:dev Jul 29, 2018
@cesalberca
Copy link
Contributor Author

Alright, I changed one compiler option: allowSyntheticDefaultImports to true which solves the default import issue (https://www.typescriptlang.org/docs/handbook/compiler-options.html). I reverted the object notation changes on the docs. I also changed the typings file so TypeScript users can use bracket notation on mocks and on provide. See tests for more info.

The only thing left to do, is determine if the docs are wrong about setting methods on the config (https://vue-test-utils.vuejs.org/api/config.html#methods).

@cesalberca
Copy link
Contributor Author

Oups, my bad, I didn't push all the changes together and it seems you merged the changes

@eddyerburgh
Copy link
Member

Ah, sorry I thought it was finished! Can you open a new PR?

@eddyerburgh
Copy link
Member

The example in methods is confusing. You can add a simpler example if you like :)

@cesalberca
Copy link
Contributor Author

Done, I create this PR: #875. Let's continue the conversation there 👍

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.

None yet

2 participants