getting ReferenceError: testData is not defined when using webdriverio Dataprovider - webdriver-io

I am getting the following error when I am trying to use a feature webdriverio comes with for dataprovider:
I have put the following in the wdio.conf.js:
dataProviders: ['./test/dataproviders/dataObject.js'],
and created dataObject.js as the following:
const dataObject = [
{
a: 0,
b: 1,
expected: 1,
description: 'returns 1 when 0 is added 1',
},
{
a: 1,
b: 2,
expected: 3,
description: 'returns 3 when 1 is added 2',
}
];
dataProvider("../specs/smoke/add.spec.js", dataObject);
and in add.spec.js, I have:
describe(verify addition - ${testData.description}, () => {
...
can you tell me what might have been wrong? will I have to import testData from somewhere? but I have read from the following file that testData is a global variable:
https://github.com/webdriverio/webdriverio/pull/4452/files#diff-65fd20fda801d80cbe511bf165b5adac8e324d3897f6bc7090aa13c943eebf8bR76
Can you please help?
[0-0] (node:54912) UnhandledPromiseRejectionWarning: ReferenceError: testData is not defined

Related

React Native can not using Spread Operator to update object in array

i have the state that control the flatList data
const [data, setData] = useState([])
i have a object like below(after get from network, it's show success in FlatList)
data = [{
'name' : 1,
},
{'name' : 2,
}]
Now i want to update first object {'name': 1} by add some key/value like this:
{ 'name' : 1, 'text' : 'this is text'}
Here is my code:
const mathched = data[0]
mathched = [
...mathched,
{'text': 'this is text'}
]
But i got error: TypeError: "mathched" is read-only
I tried other solution by set new key to object:
const newData = [...data]
const mathched = newData[0]
mathched['text'] = 'this is text'
setData(newData)
But data not changed
Can someone guide me how to use Speard Operator to done my solution? Thanks
The problem is that the state value is a read-only variable that can be modified only via the setter, setData in this case.
When you do const matched = data[0] then matched = newData[0] you are attempting to store the new value without the setter usage.
One way to go would be:
// Usign for example Lodash clone
const newClonedData = clone(data);
newClonedData[0] = { ...matched[0], {'text': 'this is text'} };
setData[newClonedData];

Unable to set nested object value in vuex state completely

I have data in database with nested object like:
[{"id":"1-368","name":"\tSolan","days":1,"daynights":2,"hotel":{"hotel_data":[{"id":1,"title":"hotel 1"}],"checkin":"","checkout":"","roomtype":""},"hotel2":{"hotel_data":[{"id":1,"title":"hotel 1"}],"checkin":"","checkout":"","roomtype":""},"specinst":"","mealplan":""},{"id":"2-54","name":"Dharamsala","days":"3","daynights":4,"hotel":{"hotel_data":[{"id":3,"title":"hotel3"}],"checkin":"","checkout":"","roomtype":""},"hotel2":{"hotel_data":[{"id":2,"title":"hotel 2"}],"checkin":"","checkout":"","roomtype":""},"specinst":"","mealplan":""}]
Now when I am trying to fetch data and try to assign to a state through mutation it get assigned incompletely like:
[{"id":"1-368","name":"\tSolan","days":1,"daynights":2,"hotel":{"hotel_data":"","checkin":"","checkout":"","roomtype":""},"hotel2":{"hotel_data":"","checkin":"","checkout":"","roomtype":""},"specinst":"","mealplan":"","date_from":"08 Jan 2020","date_to":"09 Jan 2020"},{"id":"2-54","name":"Dharamsala","days":"3","daynights":4,"hotel":{"hotel_data":"","checkin":"","checkout":"","roomtype":""},"hotel2":{"hotel_data":"","checkin":"","checkout":"","roomtype":""},"specinst":"","mealplan":"","date_from":"09 Jan 2020","date_to":"12 Jan 2020"}]
In above code you can notice hotel_data is a nested array but not able see after assigning it to vuex state.
code:
const mutations = {
setItem(state, item) {
state.item.tour_location=JSON.parse(item.tour_location);
}}
What do you see if you console.log(item.tour_location); within the setItem mutation? If the data is coming in with the correct structure, I would recommend setting up your state as a skeleton of the expected data.
For example:
Expected data: {id: 'abc', hotel: [{ prop1: '123', prop2: '234']}
Vuex state: {id: '', hotel: [{ prop1: '', prop2: '' }]}
Hope this helps.

How to extract data from nested object with pug

I'm trying to access data from nested JSON object without any javascript in PUG and product.highlights[0].heading , the index needs to looped.
JSON FORMAT
[{"id":"0.33454785604755677","title":"Product 2 Title",
"highlights":[
- {"heading":"Product 2 Heading 1","description":"Product 2 Description 1"},
- {"heading":"","description":""},
- {"heading":"","description":""},
- {"heading":"","description":""}]
}]
I tried
-var x = [0,1,2,3,4,5]
-var high =[product.highlights[0].heading,product.highlights[1].heading,product.highlights[2].heading,product.highlights[3].heading]
each val in x
-var p = high[x] // here its not considering 'x'
h3 #{p}
and directly using loop too
each i in [0,1,2,3,4,5]
h3 #{product.highlights[i].heading} //but here its not considering 'i'
Its working inside 'name' , 'for' .
but i need it to work inside:
- value=(editing ? product.highlights[0].heading:'')
each i in [1, 2, 3, 4, 5, 6]
.form-control
label(for="highlights[" + i +"][heading]") Highlights Number #{i} Heading
input(type="text",name="highlights[" + i +"][heading]",value=(editing ? product.highlights[0].heading:''))
I don't know how to access it through javascript in pug
Can someone tell me how can i do that?
-function productHeading(product,y){return product.highlights[y].heading;}
each i in [0, 1, 2, 3, 4, 5]
.form-control
label(for="highlights[" + i +"][heading]") Highlights Number #{i+1} Heading
input(type="text",name="highlights[" + i +"][heading]",value=(editing ? productHeading(product,i):''))
product stores the object found by findById method which later sent to the pug file
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const SubProductSchema = new Schema({
product_id: Schema.Types.ObjectId,
title: String,
name:{
type: String,
unique: true,
required: true
},
price:Number,
image:String,
alt: String,
quantity:Number,
description:String,
bgImage:String,
primaryImage:String,
primaryAlt: String,
primaryHeading:String,
primaryDescription:String,
highlights:[{
heading:String,
description:String,
icon:String
}],
specs:[{
heading:String,
description:String,
image:String
}],
featured:Boolean,
preOrder:Boolean,
video:Boolean
});
module.exports = mongoose.model('xxx',xxx);
Controller File
const Product = require('../models/product');
.
.
Product.findById(prodId)
.then( product => { ....
And so on .
Editing is a boolean variable , if its true the productHeading function in pug file is called and value is initalized to it else its set to '' (empty)

Karate Schema validation, does it work with nested arrays when using match contains assertion?

I'm trying to use a match on a json object by only checking for some elements. The Json object contains a nested array which seem to be the root cause for the test failing. It seems like using the 'match contains' assertion on key:values within the nested array does not work as expected and throws an error.
I've tried to use 'match contains' on first level keys and that works fine but when attempting to match keys within a nested array I get the following error message: reason: actual value has 1 more key(s) than expected
* def json = { id: 1, priority: 1, compRound: { id: 1, comp_id: 89 } }
* match json contains
"""
{
id: '#number',
priority: '#number',
compRound: {
id: '#number'
}
}
"""
As I'm using the match contains assertion, I would expect for the test to pass but instead it looks like Karate expects all key:values within the nested array to be present.
Please read this section of the docs carefully: https://github.com/intuit/karate#contains-short-cuts
* def json = { id: 1, priority: 1, compRound: { id: 1, comp_id: 89 } }
* def compRound = { id: '#number' }
* match json == { id: '#number', priority: '#number', compRound: '#(^compRound)' }

Finding the origin of Postgres/Sequelize duplicate alias error (code 42712)

I'm using Sequelize to manage by Postgres SQL database in a node.js project. I'm running into namespace errors but can't for the life of me figure out why.
The code that works:
// db variable holds initialized database connection
const link = name => ( {
through: db.define( name, {
amount: Sequelize.FLOAT,
unit: Sequelize.STRING,
dataSource: Sequelize.STRING
} ),
as: name + 's'
} )
// All model variables (Material, Component etc) have model names
// identical to their variable names (bit without capitals)
Material.belongsToMany( Material, link( 'materialchildmaterial' ) )
Component.belongsToMany( Component, link( 'componentchildcomponent' ) )
Input.belongsToMany( Input, link( 'inputchildinput' ) )
Component.belongsToMany( Component, link( 'componentchilddependency' ) )
The moment I add the following things break:
Input.belongsToMany( Component, link( 'componentchildinput' ) )
The error:
{ name: 'SequelizeDatabaseError',
parent:
{ name: 'error',
length: 177,
severity: 'ERROR',
code: '42712',
file: 'parse_relation.c',
line: '420',
routine: 'checkNameSpaceConflicts' },
original:
{ name: 'error',
length: 177,
severity: 'ERROR',
code: '42712',
file: 'parse_relation.c',
line: '420',
routine: 'checkNameSpaceConflicts' } }
From the postgres docs code 42712 stands for 'DUPLICATE ALIAS'.
My confusion: I am using unique names for everything (afaik). When I change the Input <--> Component link's name to 'randomthing' the error does not appear.
I've been stuck at this for a good day now. Any clues appreciated.