diff options
Diffstat (limited to 'doc/development/fe_guide')
-rw-r--r-- | doc/development/fe_guide/axios.md | 23 | ||||
-rw-r--r-- | doc/development/fe_guide/style_guide_js.md | 37 | ||||
-rw-r--r-- | doc/development/fe_guide/style_guide_scss.md | 2 | ||||
-rw-r--r-- | doc/development/fe_guide/vue.md | 2 |
4 files changed, 35 insertions, 29 deletions
diff --git a/doc/development/fe_guide/axios.md b/doc/development/fe_guide/axios.md index 1daa6758171..0d9397c3bd5 100644 --- a/doc/development/fe_guide/axios.md +++ b/doc/development/fe_guide/axios.md @@ -27,10 +27,23 @@ This exported module should be used instead of directly using `axios` to ensure }); ``` -## Mock axios response on tests +## Mock axios response in tests -To help us mock the responses we need we use [axios-mock-adapter][axios-mock-adapter] +To help us mock the responses we are using [axios-mock-adapter][axios-mock-adapter]. +Advantages over [`spyOn()`]: + +- no need to create response objects +- does not allow call through (which we want to avoid) +- simple API to test error cases +- provides `replyOnce()` to allow for different responses + +We have also decided against using [axios interceptors] because they are not suitable for mocking. + +[axios interceptors]: https://github.com/axios/axios#interceptors +[`spyOn()`]: https://jasmine.github.io/api/edge/global.html#spyOn + +### Example ```javascript import axios from '~/lib/utils/axios_utils'; @@ -50,13 +63,13 @@ To help us mock the responses we need we use [axios-mock-adapter][axios-mock-ada }); afterEach(() => { - mock.reset(); + mock.restore(); }); ``` -### Mock poll requests on tests with axios +### Mock poll requests in tests with axios -Because polling function requires an header object, we need to always include an object as the third argument: +Because polling function requires a header object, we need to always include an object as the third argument: ```javascript mock.onGet('/users').reply(200, { foo: 'bar' }, {}); diff --git a/doc/development/fe_guide/style_guide_js.md b/doc/development/fe_guide/style_guide_js.md index 1cd66f27492..02773162801 100644 --- a/doc/development/fe_guide/style_guide_js.md +++ b/doc/development/fe_guide/style_guide_js.md @@ -101,16 +101,16 @@ followed by any global declarations, then a blank newline prior to any imports o ``` Import statements are following usual naming guidelines, for example object literals use camel case: - + ```javascript // some_object file export default { key: 'value', }; - + // bad import ObjectLiteral from 'some_object'; - + // good import objectLiteral from 'some_object'; ``` @@ -255,6 +255,10 @@ A forEach will cause side effects, it will be mutating the array being iterated. ### Vue.js +#### `eslint-vue-plugin` +We default to [eslint-vue-plugin][eslint-plugin-vue], with the `plugin:vue/recommended`. +Please check this [rules][eslint-plugin-vue-rules] for more documentation. + #### Basic Rules 1. The service has it's own file 1. The store has it's own file @@ -360,6 +364,10 @@ A forEach will cause side effects, it will be mutating the array being iterated. <component bar="bar" /> + + // bad + <component + bar="bar" /> ``` #### Quotes @@ -509,25 +517,7 @@ On those a default key should not be provided. ``` 1. Properties in a Vue Component: - 1. `name` - 1. `props` - 1. `mixins` - 1. `directives` - 1. `data` - 1. `components` - 1. `computedProps` - 1. `methods` - 1. `beforeCreate` - 1. `created` - 1. `beforeMount` - 1. `mounted` - 1. `beforeUpdate` - 1. `updated` - 1. `activated` - 1. `deactivated` - 1. `beforeDestroy` - 1. `destroyed` - + Check [order of properties in components rule][vue-order]. #### Vue and Bootstrap @@ -582,3 +572,6 @@ The goal of this accord is to make sure we are all on the same page. [eslintrc]: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/.eslintrc [eslint-this]: http://eslint.org/docs/rules/class-methods-use-this [eslint-new]: http://eslint.org/docs/rules/no-new +[eslint-plugin-vue]: https://github.com/vuejs/eslint-plugin-vue +[eslint-plugin-vue-rules]: https://github.com/vuejs/eslint-plugin-vue#bulb-rules +[vue-order]: https://github.com/vuejs/eslint-plugin-vue/blob/master/docs/rules/order-in-components.md diff --git a/doc/development/fe_guide/style_guide_scss.md b/doc/development/fe_guide/style_guide_scss.md index 77b308c4a43..86a8b4135af 100644 --- a/doc/development/fe_guide/style_guide_scss.md +++ b/doc/development/fe_guide/style_guide_scss.md @@ -216,7 +216,7 @@ If you want a line or set of lines to be ignored by the linter, you can use ```scss // This lint rule is disabled because the class name comes from a gem. // scss-lint:disable SelectorFormat -.ui_charcoal { +.ui_indigo { background-color: #333; } // scss-lint:enable SelectorFormat diff --git a/doc/development/fe_guide/vue.md b/doc/development/fe_guide/vue.md index 6e9f18dd1c3..6c93c29124d 100644 --- a/doc/development/fe_guide/vue.md +++ b/doc/development/fe_guide/vue.md @@ -456,7 +456,7 @@ describe('Todos App', () => { }); ``` #### `mountComponent` helper -There is an helper in `spec/javascripts/helpers/vue_mount_component_helper.js` that allows you to mount a component with the given props: +There is a helper in `spec/javascripts/helpers/vue_mount_component_helper.js` that allows you to mount a component with the given props: ```javascript import Vue from 'vue'; |