question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not select <router-view> component

See original GitHub issue

I’m trying to test certain parts of my applications computed properties such as locale or form validation results which are contained on the component loaded into the <router-view> component

You can see in the screenshot

https://imgur.com/PswNqQi/

my default route view loads up my welcome component, using VueSelector() how do I actually select this component to access the state/prop/ computed data.

If i do

const root = VueSelector() const rootVue = await root.getVue()

This selects the <QLayout> component

If I do

const welcome = VueSelector(‘welcome’) const welcomeVue = await welcome.getVue()

I get a

node.vue undefined

I’ve tried passing all sorts of combinations into VueSelector like

VueSelector(‘q-layout welcome’) VueSelector(‘router-view’) VueSelector(‘q-layout router-view’) VueSelector(‘router-view welcome’)

None of which actually select the component served from the route. I can however select any component nested within welcome such as the Login component like

const login = VueSelector(‘login’) const loginVue = await login.getVue()

await t .expect(loginVue.computed.isAuthenticated).eql(false) .expect(loginVue.props.facebook).eql(true)

Any help is really appreciated because otherwise I can’t test alot of data on any components server from the router

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
miherlosevcommented, Oct 30, 2017

Yes. You can do it using a ClientFunction feature. I’ve created an example

import { Selector, ClientFunction } from 'testcafe';

fixture `Vue properties`
	.page('http://localhost:8080/test/data/');
	
test('get Vue specific properties', async t => {
	const node = Selector('#app');
	
    const getVueProperties = ClientFunction(() => {
		function getData (instance, prop) {
            const result = {};

            Object.keys(prop).forEach(key => {
                result[key] = instance[key];
            });


            return result;
        }
		
		 function getProps (instance) {
            return getData(instance, instance.$options.props || {});
        }

        function getState (instance) {
            const props   = instance._props || instance.$options.props;
            const getters = instance.$options.vuex && instance.$options.vuex.getters;
            const result  = {};

            Object.keys(instance._data)
                .filter(key => !(props && key in props) && !(getters && key in getters))
                .forEach(key => {
                    result[key] = instance._data[key];
                });

            return result;
        }

        function getComputed (instance) {
            return getData(instance, instance.$options.computed || {});
        }
		
		var nodeVue = node().__vue__;
		
		if (!nodeVue)
            return null;
		
		var props    = getProps(nodeVue);
        var state    = getState(nodeVue);
        var computed = getComputed(nodeVue);
		
		return {
			props: props,
			state: state,
			computed: computed
		};
	}, { dependencies: { node } });	
	
	const vueProperties = await getVueProperties();
	
	console.log(vueProperties);
});	
0reactions
nshCorecommented, Oct 27, 2017

is there a way to access vue computed properties with the default selectors?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not show the components in <router-view/> - Stack Overflow
My router/index.js. import innerView1 from '@/components/mainViews/innerView1' import innerView2_1 from '@ ...
Read more >
Understand Routing in Vue.js With Examples | by SaidHayani
I shall choose a Cosmo, click Ctrl + U to view code source and just copy the Navbar , we just need navbar,...
Read more >
Testing Vue Router
This article will present two ways to test an application using Vue Router: ... The <router-link> and <router-view> component are not found.
Read more >
How To Navigate Between Views with Vue Router
For the purpose of this tutorial, do not select Vue Router when creating ... any component associated with a route where <router-view />...
Read more >
Vue Router: A Tutorial for Vue 3 - Vue Mastery
Why Vue Router? Vue is powerful for creating Single Page Applications: highly interactive webpages that don't refresh when you change from page ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found