Testing Enyo Applications - karma-jasmine

I have an enyo kind like this:
enyo.kind({
name:"branding", components: [
{name: "appName", content:"Stars of the East", classes:"heading"},
{content:AppConfig.tagline, classes:"subHeading"}]
});
I am trying to test this kind with the following jasmine describe.
describe("Test Branding Kind", function() {
it("should see enyo component from jasmine", function() {
var branding = enyo.kind({
kind: "branding"
});
expect(branding.$.appName.getContent()).toBe("Stars of the East");
})
});
I am getting an error. Can anyone guide me ?

You need to put your sub-components in a components array (you already have the closing bracket for the array in your code):
enyo.kind({
name:"branding", components: [
{name: "appName", content:"Stars of the East", classes:"heading"},
{content:AppConfig.tagline, classes:"subHeading"}]
});

You need to actually instantiate your kind to test it. enyo.kind() only creates the template. Try:
describe("Test Branding Kind", function() {
it("should see enyo component from jasmine", function() {
var localBranding = new branding();
expect(localBranding.$.appName.getContent()).toBe("Stars of the East");
})
});
You will also have to fix the problem that Art pointed out where you do not have the components block.
You will probably also need to actually render your components if they have UI elements you want to check. You may want to change the localBranding line to:
var localBranding = new branding().renderInto(<some element on your page>);
Finally, we suggest that kind names should be uppercase to distinguish them from instance names. name: "branding" would be name: "Branding" if you follow our advice.

Related

dynamic rendering compilation of vue2 templates with components embedded

I hope somebody can help me with my vue.js question regarding version 2.6.14
I created a component "dynamiccontent" capable of displaying html string generated from a backend api (with vue variables/functions in). the component utilizes vue.compile and render functions. it works great for the test case "slide working" in the app when I use my code for normal html tags.
here is the test function
Vue.component("test-slide", {
template:
'<div :key="slide.id"><dynamiccontent v-bind:slide="slide"></dynamiccontent></div>',
props: ["slide"]
});
var vm = new Vue({
el: "#player",
template:
"<div>working: <test-slide v-bind:slide='slideworking'></test-slide><br> problem: <test-slide v-bind:slide='slidenotworking'></test-slide></div>",
methods: {
test() {
return "test";
}
},
data: function () {
return {
slideworking: {
id: "dkd",
content:
"<div>test {{this.getDynamic()}}<div><div>test {{this.getDynamic()}}<div>test {{this.getDynamic()}}</div></div></div></div>"
},
slidenotworking: {
id: "dkd",
content:
"<div>test {{this.getDynamic()}}<test-component>{{this.getDynamic()}}<test-component>test {{this.getDynamic()}}<test-component>test {{this.getDynamic()}}</test-component></test-component></test-component></div>"
}
};
}
});
as soon es I try to use variables in cascaded components (see the sample data "slide notworking", which uses vue components as well, in this example testcomponent) the compile function seems to ignore all the Childs.
The Problem as a codepen with the demo source
codepen.io
What is expected?
vue.compile should compile the child components as well
What is actually happening?
vue compile seems to stop at the first vue component

v-html of Vue doesn't support promise,etc,all of vue binding value doesn't support promise,is there a solution?

code in my project
the formatter method, may include async method, and may be use async and await,when i use, page render uncorrectly。Is there a solution?
Welcome to Stackoverflow. Please do not send code in images, as this is very inconvenient to answer. And please do not add links to external pages unless it is an official documentation.
Vue only binds variables which are defined in the data section.
So this should work:
export default {
data() {
return {
scope: {
data: {row: []}
but this will not bind the row records:
export default {
data() {
return {
scope: {} // does not work with scope.data.row

How do I properly import multiple components dynamically and use them in Nuxt?

I need to implement dynamic pages in a Nuxt + CMS bundle.
I send the URL to the server and if such a page exists I receive the data.
The data contains a list of components that I need to use, the number of components can be different.
I need to dynamically import these components and use them on the page.
I don't fully understand how I can properly import these components and use them.
I know that I can use the global registration of components, but in this case I am interested in dynamic imports.
Here is a demo that describes the approximate logic of my application.
https://codesandbox.io/s/dank-water-zvwmu?file=%2Fpages%2F_.vue
Here is a github issue that may be useful for you: https://github.com/nuxt/components/issues/227#issuecomment-902013353
I've used something like this before
<nuxt-dynamic :name="icon"></nuxt-dynamic>
to load dynamic SVG depending of the icon prop thanks to dynamic.
Since now, it is baked-in you should be able to do
<component :is="componentId" />
but it looks like it is costly in terms of performance.
This is of course based on Nuxt components and auto-importing them.
Also, if you want to import those from anywhere you wish, you can follow my answer here.
I used this solution. I get all the necessary data in the asyncData hook and then import the components in the created () hook
https://codesandbox.io/s/codesandbox-nuxt-uidc7?file=/pages/index.vue
asyncData({ route, redirect }) {
const dataFromServer = [
{
path: "/about",
componentName: 'myComponent'
},
];
const componentData = dataFromServer.find(
(data) => data.path === route.path
);
return { componentData };
},
data() {
return {
selectedRouteData: null,
componentData: {},
importedComponents: []
};
},
created() {
this.importComponent();
},
methods: {
async importComponent() {
const comp = await import(`~/folder/${this.componentData.componentName}.vue`);
this.importedComponents.push(comp.default);
}

Page reload causes Vuex getter to return undefined

Using Vue.js (Vuetify for FE).
A page reload causes the getter in Vuex to fail with pulling required data from the store. The getter returns undefined. The code can be found on GitHub at: https://github.com/tineich/timmyskittys/tree/master/src
Please see the full details on this issue at timmyskittys.netlify.com/stage1. This page has complete info on the issue and instructions on how to view the issue.
Note, there is mention of www.timmyskittys.com in the issue description. This is the main site. timmyskittys.netlify.com is my test site. So, they are the same for all intents and purposes. But, my demo of this issue is at the Netlify site.
I read the complete issue in the website you mentioned. It's a generic case.
Say, for cat details page url: www.timmyskittys.com/stage2/:id.
Now in Per-Route Guard beforeEnter() you can set the cat-id in store. Then from your component call the api using the cat-id (read from getters)
I found the solution to my issue:
I had to move the call of the action which calls the mutation that loads the .json file (dbdata.json) into a computed() within App.vue. This was originally done in Stage1.vue.
Thanks all for responding.
I had the same issue and my "fix" if it can be called that was to make a timer, so to give the store time to get things right, like so:
<v-treeview
:items="items"
:load-children="setChildren"
/>
</template>
<script>
import { mapGetters } from 'vuex'
const pause = ms => new Promise(resolve => setTimeout(resolve, ms))
export default {
data () {
return {
children: []
}
},
computed: {
...mapGetters('app', ['services']),
items () {
return [{
id: 0,
name: 'Services',
children: this.children
}]
}
},
methods: {
async setChildren () {
await pause(1000)
this.children.push(...this.services)
}
}
}
</script>
Even though this is far from ideal, it works.

Find by data-dojo-id on Intern-runner functional test?

Is there a way to grab a reference to a widget instance by data-dojo-id on an Intern functional test running on a standalone server?
Yes, Dojo released a dijit-intern-helper module that you can include in your tests to help with this:
define([
'intern!object',
'intern/chai!assert',
'intern/dojo/node!dijit-intern-helper/helpers/dijit',
'require'
], function (registerSuite, assert, dijit, require) {
var url = '../../index.html';
registerSuite({
name: 'Todo (functional)',
'get widget node': function () {
return this.remote
.get(require.toUrl(url))
.then(dijit.nodeById('yourWidgetId', 'rootNodeToLookUnder'))
.getProperty('value')
.then(function (val) {
assert.ok(val == 'Test :)');
});
}
});
});
You can read more about it on this Sitepen blog post or straight on the project Github page.