Closed alex-di closed 6 years ago
@alex-di I believe this is impossible because of laziness. Variables doesn't have influence on the tests flow and are created when you access them first time. So, imagine case:
describe('Suite', function() {
def('user', function(done) {
var user = new User();
user.save().finally(done)
return user;
});
it('creates user', function() {
expect($user).to.have.key('id'); // at this moment "user" variable has been just created and can't stop the execution of the test function which currently is running
});
});
Even if we do this hard implementation, we will loose laziness and variable's composition which are very handy featutes.
The solution may be in the area of async functions. Something like this:
describe('Suite', function() {
def('user', async function() {
var user = new User();
await user.save();
return user;
});
it('creates user', async function() {
var user = await $user;
expect(user).to.have.key('id');
});
});
As a current workaround I suggest to use beforeEach
block which can alter tests flow:
describe('Suite', function() {
def('user', function() {
return new User();
});
beforeEach(function(done) {
$user.save(done);
});
it('creates user', function() {
expect($user).to.have.key('id');
});
});
Anyway I'm opened to suggestions regarding possible implementations of such behavior
Hey, folks. It would be nice to do async def, my issue is that I need to save instance cuz it triggers a lot of calcs. Something like that usage: