I was trying to skip the tests based on API failure for detox tests in which I am using jest as test runner
const itif = (condition) => condition ? it : it.skip;
const itif = (condition) => condition ? it : it.skip;
describe('Example', () => {
let condition1;
let condition2;
beforeEach(async () => {
condition1 = await getResponseverifyArticles() ? true :false
condition2 = await getNumberOfFollowers() ? true :false
await device.launchApp();
});
console.log(condtion1) // --> giving undefined
//so first test always skips
itif(condition1)('should verify articles1' ,async() => {
await expect(element(by.text('Articles:'))).toBeVisible()
await getResponseverifyArticles()
await expect(element(by.text('Articles:'))).toBeVisible()
});
//same as aboue
itif(condition2)('should see Articles screen2', async () => {
await expect(element(by.text('Articles:'))).toBeVisible()
await getNumberOfFollowers()
});
});
async function getArticles() {
let articles;
await axios
.get('https://raw.githubusercontent.com/adhithiravi/React-Hooks-Examples/master/testAPI.json')
.then(response => {
if (response.status === 200 || response.status === 201) {
articles = response.data.articles
}
})
.catch(error => {
console.error("error Message :",error.response.data)
});
return articles
}
const getResponseverifyArticles = async()=>{
const res = await getArticles();
for (let item of res) {
await expect(element(by.text(item.title))).toBeVisible()
}
}
async function getNumberOfFollowers() {
let nOfFollowers
await axios
.get('https://api.github.com/users/janbodnar')
.then(response => {
if (response.status === 200 || response.status === 201) {
nOfFollowers = response.data.followers;
}
})
.catch(error => {
console.warn("Requested URL :",error.response)
});
return nOfFollowers
}
getNumberOfFollowers()
In this way, I was trying to skip the tests...but not able to access the condions from beforeAll block. Is there any way to access those conditions dynamically.