Ad
Conditional Test Case In Jasmine
I am writing Jasmine. I want that when the response from the site is ok (site uploaded- pending 200).
Run the it's (test cases) in spec and when the site is failed to load the site the it's (test cases) will not run.
I check the response from site in before all function.
And now in each it that make different thing I check the condition if the response (saved in global var) is true
How can I do it in global fun like before each?
let response;
describe('', ()=>{
beforeAll (async () => {
//this function return the statusCode of http request
response= await sendQuery('Http://...');
})
beforeEach(async(), =>{
});
it('', async()=> {
if (response = 200){
//do somsing 1...
}
it('', async()=> {
if (response = 200){
//do somsing 2...
}
it('', async()=> {
if (response = 200){
//do somsing 3...
}
v
it('', async()=> {
if (response = 200){
//do somsing 4...
}
it('', async()=> {
if (response = 200){
//do somsing 5...
}
it('', async()=> {
if (response = 200){
//do somsing 6...
}
Ad
Answer
something like this in your config
async onPrepare() {
global.response = await sendQuery('Http://...');
if (global.response !== 200) {
throw new Error(`Status is ${response}`); // may not be needed actually, but I'll leave it
await browser.close();
await process.exit(1);
}
}
global.response
will be available in your specs
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad