Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

before hook inside describe is not load #4

Open
otoniel-isidoro opened this issue Feb 6, 2017 · 1 comment
Open

before hook inside describe is not load #4

otoniel-isidoro opened this issue Feb 6, 2017 · 1 comment
Labels

Comments

@otoniel-isidoro
Copy link

When I use the before block inside the describe block the code inside the before block isn't called but if I put the before block outside of the describe block it is called normally. Is this the normal behaviour?

My script:

eval(globals.postmanBDD);

var schema = {"type":"array","minItems":3,"items":{"type":"object","properties":{"id":{"type":"integer"},"action_code":{"type":["string","null"]},"source":{"type":"string"},"event_extra_info":{"type":"object","properties":{"tag":{"type":"string"}}},"created_at":{"type":"string"}},"required":["id","action_code","source","event_extra_info","created_at"],"additionalProperties":false}};
    

describe('Approved Calculators API', function(){
    before('load schema', function(){ 
        // For now the schema will be maintened on the script too
        console.log("schema:", globals.schema);
        if(globals.schema !== null && globals.schema !== undefined) {
            schema = JSON.parse(globals.schema);
        }
    });
   
    
   it('should return a valid JSON response', function(){
     expect(response).to.be.json;
    //  expect(response.body).to.not.be.empty;
     expect(response.body).to.have.schema(schema);  
   }); 
   
   it('should return 200 as status code', function(){
     expect(response).to.have.status(200);
   });
   
   it('should not take more than 200 miliseconds to load', function(){
     expect(response.time).to.be.at.most(200);
   });
   
   after('clean', function(){
     postman.clearGlobalVariable("schema"); 
   });
});
@JamesMessinger
Copy link
Owner

Good catch. The code is currently written with the expectation that any hooks (e.g. before, after, etc.) will be written before anything else, but there's no reason I can't make it work for this scenario too.

The before hook runs one time, before the very first describe block. So, currently, if you define a before hook after the first describe block, then the hook will never trigger. But I'll change it so that if a describe block has already occurred, then the before hook will just run immediately.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants