-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/unit test #2
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
Conversation
|
The coverace fails because actually I wasn't able to test completely the |
nirazul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort, it's a very nice first step for a core component library!
A few questions:
- Do we really need to check in the dist file
dist/index.esm.js? Is there a reason?
The rest of the questions is inlined, feel free to ask, any time!
|
|
||
| import { createLocalVue, shallowMount } from '@vue/test-utils'; | ||
| import { expect } from 'chai'; | ||
| import { Modal } from '../../../'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks sort of an error to me? Is it like omitting index.js?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the node require algo will import always what we define in the main key of the package.json. Now if today we use main: "dist/index.cjs.js" and tomorrow main: "my-fancy-lib.js" we can avoid to rewrite all the paths in our unit test.
Sidenote: it's impossible to unit test vue components in node without bundling them
src/components/modal/modal.spec.js
Outdated
| @@ -0,0 +1,67 @@ | |||
| /* eslint-disable no-unused-expressions, max-nested-callbacks */ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the unused expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use chaijs expectations you might want to write:
expect('Rouven').to.be.ok
expect(['Gian', 'Luc', 'a'].to.have.a.lengthIn this case eslint complains because these chains are not called explicitly :(
src/mixins/bem/bem.spec.js
Outdated
| const vm = new localVue(getDummyComponentProps(bemMixin(ROOT_CLASS))); | ||
|
|
||
| expect(vm.bemFacets).to.be.an('array'); | ||
| expect(vm.bemFacets).to.include(`${ ROOT_CLASS }${ DEFAULT_OPTIONS.bemModifierMarker }${ DEFAULT_OPTIONS.defaultFacet }`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd advise to expressively write down the expected result and avoid any kind of concat or logic within a test:
expect(vm.bemFacets).to.include('root__base');
This makes it much more readable and direct and avoids having subtle bugs within our unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense
| @@ -0,0 +1,60 @@ | |||
| import Vue from 'vue'; | |||
| import { CLOSE_OVERLAY, MOUNT_OVERLAY, OPEN_OVERLAY, PREPARE_CLOSE_OVERLAY, UNMOUNT_OVERLAY } from '../mutation-types'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, you wanted to write it expressively, rather than import * as types from '../mutation-types'? Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it's just my personal preference
| * Trigger close action for an overlay | ||
| * @param {Object} context - A vuex action context | ||
| * @param {Object} payload - A vuex action payload | ||
| * @return {Promise} promise resolved once the last overlay commit will be dispatched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what this should mean, what is the "last overlay commit"?
This text should describe what I get when I invoke the function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly I am still not really happy with this reducer. It dispatches too many asynchronous commits. I guess we will need to refactor it anyways
src/modules/overlay/module.spec.js
Outdated
| @@ -0,0 +1,263 @@ | |||
| /* eslint-disable max-nested-callbacks */ | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could disable max-nested-callbacks in the eslint config for all *.spec* files with the oerrides option:
https://eslint.org/docs/user-guide/configuring#disabling-rules-only-for-a-group-of-files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah wow cool I didn't know it
This is a big PR.
in a nutshell it improves the following things:
@nirazul @faebeee Please let me know if you have questions