Jest or Cypress abstracted code - how to print out the correct test line in a failed test - testing

When having reusable code in tests, one could abstract it to share it between tests.
When the code fails on the assertion in the abstraction (function) it prints out the line from the abstracted method, not the part of the test. If the abstraction is being used multiple times in a test, one cannot know where in the test the error occurred.
What I wonder is how this could be configured to report errors correctly.
E.g. as in this cypress test example
export function assertAssignmentStatus(assertionString: string, status: string) {
cy.findByText(assertionString)
.parents('[data-testid="tableRow"]')
.within(() => {
cy.findByTestId('statusColumn').should('have.text', status);
});
}
it('has the correct status, () => {
... test bootstrap
assertAssignmentStatus('some-selector', 'some status');
assertAssignmentStatus('some-selector 1', 'some status 1');
assertAssignmentStatus('some-selector 2', 'some status 2');
assertAssignmentStatus('some-selector 3', 'some status 3');
... some event execution
assertAssignmentStatus('some-selector', 'some status 1');
assertAssignmentStatus('some-selector 1', 'some status 2');
assertAssignmentStatus('some-selector 2', 'some status');
assertAssignmentStatus('some-selector 3', 'some status 3');
})

Related

React native how to update multiple state values

Here is the user details which I want to update values when user enters data in Textinput
const [details, setDetails] = React.useState({
isValidName: true,
isValidMobile: true,
isValidEmail: true,
isValidGSTIN: true,
isValidPAN: true,
name: '',
mobile: '',
email: '',
company: '',
baddr1: '',
baddr12: '',
bcity: '',
bpincode: '',
bstate: ' TAMIL NADU',
bcountry: 'INDIA',
saddr1: '',
saddr2: '',
sbranch: '',
sgstin: '',
scity: '',
spincode: '',
sstate: '',
scountry: '',
pan: '',
gstin: '',
userlevel: '',
});
//In this method i am updating values each time when user enters data
const submitBillAddress = (data, type) => {
console.log('bill', type);
switch(type){
case 'addr1':
setDetails((prevState)=>{
return({
...prevState,
baddr1: data
});
});
break;
}
console.log('billdetails', details);
};
return (
<View>
<TextInput
style={styles.TextInputStyleClass}
placeholder="Address Line 1"
value={sameAddress?null:details.baddr1}
onChangeText={val => submitBillAddress(val, 'addr1')}
/>
</View>
)
I am new to React Native application development and I know this question is basic but I am not getting exact output. Here I have one Textinput in which I am entering data that I wanted to store in details.
The issue is if I enter data in textinput it's not updating value in details. Let's say I am entering 'C' in Textinput if I try to check the value in console the value of details.baddr1='' it's empty, Second time if I enter value 'H' on that time in console the value of details.baddr1='C'. Instead of showing the value details.baddr1='CH' it's showing previously entered value.
How can I fix this issue?
I'm guessing this is for a form of some sort. In that case, a package is your best bet I believe. While what you're trying to achieve is possible without a package, using a package is far less painful in the long run for your app.
Please check out formik or react-hook-form.
They're both decent.

getting ReferenceError: testData is not defined when using webdriverio Dataprovider

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

vue-i18n this.$tc is not a function

My lang file:
AccountNotifications: {
createdWithName: 'Account «{account}» created',
created: 'Account created | Accounts created',
}
my submit method
submit()
this.$notifications.add({
type: 'success',
html: accounts.length === 1
? this.$tc('AccountNotifications.created', 1)
: this.$tc('AccountNotifications.created', 2),
});
My output
app.js:290949 TypeError: this.$tc is not a function
Whats wrong?
$tc() is not actually needed. The $t() function supports pluralization now.

how helpers.translate('SOME_KEY') works?

I am wondering that how helpers.translate('SOME_KEY'); works in protractor?
i am using it like:
expect(element(by.css('.contact_tag')).getText()).toEqual('CONTACT');
here 'CONTACT' string translated in English as 'contact details'. i am getting the following output
output:
Expected 'contact details' to equal Object({ $$state: Object({ status: 0 }), catch: Object({ }), finally: Object({ }), then: Object({ }) }).
somebody please explain me that how this helpers.translate works? from where it takes this CONTACT translate string?

This socket has been ended by the other party] code: 'EPIPE'

I'm receiving this error after some actions, for example, in ~10 seconds after successful insert:
Error: This socket has been ended by the other party] code: 'EPIPE'
Means, first time i'm inserting it fine, but when i'm attempting to do insert something else, or retrieve data or ... etc - i'm getting this error.
It doesn't happen after idle. Only after some actions. Some times after retrieval and always after insert.
Insert query example:
var query = "insert into public.comment (text,owner,owner_name,resource_type, resource_id,parent) values ('some text','40c28840-4241-4b7a-b339-29d9759693eb','UserName','note','33695e8b-5cff-42a1-9c64-7c0a3cd0f411','8a416406-c848-46e0-ac14-6aa6bcdb5044') returning owner,owner_name,text,parent,created,id"
client.query(query, function(err, result) {
done();
if (err) {
socket.emit('userError', 0) // unknownError
return console.error('ERROR '+query, err);
}
console.log(result)
});
here is the same query, i've formatted it a bit to make it easier to read:
insert into public.comment (
text,
owner,
owner_name,
resource_type,
resource_id,
parent
)
values (
'some text',
'40c28840-4241-4b7a-b339-29d9759693eb',
'UserName',
'note',
'33695e8b-5cff-42a1-9c64-7c0a3cd0f411',
'8a416406-c848-46e0-ac14-6aa6bcdb5044'
) returning owner,owner_name,text,parent,created,id