Last active
June 19, 2019 08:42
-
-
Save fraaalk/0d034b00e4524e4d0163288e030b4d80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script> | |
| import _mixins from './mixins' | |
| export default { | |
| mixins: [..._mixins] | |
| methods: { | |
| activate() { | |
| this.ensureJsLib('foo', 'bar') | |
| } | |
| } | |
| } | |
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| methods: { | |
| /** | |
| * Checks for the lib name in the window object | |
| * and loads the script source in case its missing | |
| * @param {String} libName | |
| * @param {String} libSource | |
| */ | |
| ensureJsLib(libName, libSource) { | |
| if (!window[libName]) { | |
| const externalLib = document.createElement('script') | |
| externalLib.setAttribute('src', libSource) | |
| document.head.appendChild(externalLib) | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import _props from './props' | |
| import _computed from './computed' | |
| import _components from './components' | |
| import _data from './data' | |
| import _methods from './methods' | |
| export default [ | |
| _data, | |
| _components, | |
| _props, | |
| _computed, | |
| _methods | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { shallowMount } from '@vue/test-utils' | |
| import Component from '@/components/component.vue' | |
| const factory = (params = {}) => { | |
| return shallowMount(Component, params) | |
| } | |
| describe('Component', () => { | |
| it('loads lib on activate', () => { | |
| const spy = jest.spyOn(Component.methods, 'ensureJsLib') | |
| const wrapper = factory() | |
| wrapper.vm.activate() | |
| expect(spy).toHaveBeenCalled() | |
| spy.mockClear() | |
| }) | |
| }) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cannot spy the ensureJsLib property because it is not a function; undefined given instead