how do I do a deepEqual assertion on codewars? - qunit

I think they are using qunitjs, but I'm not sure.
Test.assertDeepEqual(solution('abc'), ['ab', 'c_'], 'abc failed')
TypeError: Object #<Object> has no method 'assertDeepEqual'

If they are using QUnit then the correct syntax would be:
QUnit.test("some test name", function(assert) {
assert.deepEqual(solution('abc'), ['ab', 'c_'], 'abc failed');
});
So either they are not using QUnit, or they are and do not have the syntax correct.

Related

cy.url().should() failing with type error

We have the following piece of code that fails intermittently.
cy.url().then((url) => {
if (url.includes('https://app') || url.includes('https://auth')) {
cy.url().should('match', /\/agent|\/worker/, { timeout: 30000 }) ^
}
})
The failure happens in the second cy.url() command where the should match condition fails with the error "[object Object]: expected undefined to match". We only see this error every once or so in 10 time.
Instead of again using cy.url(), use the previous url you extracted with cy.wrap(), something like this:
cy.url().then((url) => {
if (url.includes('https://app') || url.includes('https://auth')) {
cy.wrap(url).should('match', /\/agent|\/worker/, {timeout: 30000})
}
})
I'm not sure of the reason for covering multiple scenarios like this would be.
Also, you don't give an example of the url, I'm going to assume your regex is to check the pathname of the url.
cy.location('pathname').should('match', /\/agent|\/worker/i)

webdriverio mocha How write function in wdio.conf.js if a test fails

I am trying to write a function in wdio.conf.js that executes when a test passes.
At the end of the test, it shows all of the tests passing, however it never hits the console.log("testpassed") code shown here:
afterTest: function (test) {
if (test.passed === true) {
console.log("testpassed")
}
},
If I console.log - 'test' - it prints [object Object].
However, if I console log test.passed it prints undefined.
At the end of the test it shows all tests as passed.
What am I doing wrong?
Further investigation: These are the only keys returned in the 'test' array:
type,title,fn,body,async,sync,_timeout,_slow,_retries,timedOut,_currentRetry,pending,file,parent,ctx,_events,_eventsCount,callback,timer
So there doesn't seem to be a key for test.passed
afterTest: function (test, context, { passed }) {
if(passed){
console.log("THE TEST PASSED");
}
},

WebdriverIO waitUntil example is not working

I am trying to use Webdriverio v5 and I have problems to run the example for waitUntil https://webdriver.io/docs/api/browser/waitUntil.html
it('should wait until text has changed', () => {
browser.waitUntil(() => {
return $('#someText').getText() === 'I am now different'
}, 5000, 'expected text to be different after 5s');
});
the error is saying
Type 'boolean' is not assignable to type 'Promise<boolean>'
anyone else is facing the same problem?
or how to fix it?
while in v4 everything works as expected
It looks like you're using typescript in your tests. Make sure you've gone through the entire typescript/webdriverio setup: https://webdriver.io/docs/typescript.html
In this case, I think you need to add wdio-sync to your compilerOptions types setting.
"compilerOptions": {
"types": ["node", "#wdio/sync"]
}

How to unit test graphql query/mutation error with Mocha and Chai?

Since graphql error is not an standard Error. It's a GraphQLError
I can't figure out how to write unit test when graphql query/mutation throw an exception.
Here is my try:
it('should throw an error when lack of "id" argument for user query', async () => {
const body = {
query: `
query user{
user {
id
name
}
}
`
};
try {
const actualValue = await rp(body);
} catch (err) {
logger.error(err);
}
// logger.info(actualValue);
expect(1).to.be.equal(1);
// expect(actualValue).to.throw()
});
I found some tests in graphql.js repo. https://github.com/graphql/graphql-js/blob/master/src/tests/starWarsQuery-test.js#L393
But I think the way they test the query/mutation error is not correct.
They just do a deep equal with the error. But before running the test suites, how do I know the error data structure like locations: [{ line: 5, column: 13 }],? Maybe I should use snapshot testing so that I don't need to know the error data structure?
Check this package https://github.com/EasyGraphQL/easygraphql-tester there is an example with mocha and chai on the documentation

Nightwatch Unable to locate element using xpath

I am new to Nightwatch and trying to write a simple test. I am getting the following error.
ERROR: Unable to locate element: "//label[data-id="CC"]" using: xpath
let suite = {
"Test 1.": function (client) {
client.useXpath();
page = client.page.configure.deviceProperties.default();
page.navigate();
page.waitForLoader();
},
"column selector": function(client){
page
.verify.containsText('//label[data-id="CC"]', 'CC')
client.pause(100);
}
I also have tried with
'label[data-id="CC"]'
'label[#data-id="CC"]'
What am I doing wrong? Thanks in advance.
-dj
the attribute must contains prefix # using xpath (as you have specified)
like "//label[#data-id='CC']" which should works
and in CSS it looks like "label[data-id='CC']"
add a waiting step before test like waitForElement
[using xpath]
page.waitForElementVisible("//label[#data-id='CC']", 2000, false, function(result){
if (result.status === 0) {
page.verify.containsText("//label[#data-id='CC']", 'CC')
}
});
or expect :
page.expect.element("//label[#data-id='CC']").text.to.contain('CC').before(2000);
use ('//label[#data-id="CC"]', 'CC'), and you should try your xpath in the browser console to test whether the xpath is correct or not.

Resources