Skip to content

Instantly share code, notes, and snippets.

@stalniy
Created June 25, 2018 18:18
Show Gist options
  • Save stalniy/5ff797dfa17f71ff02c89d252df45a1b to your computer and use it in GitHub Desktop.
Save stalniy/5ff797dfa17f71ff02c89d252df45a1b to your computer and use it in GitHub Desktop.
Write tests with lazy variables
describe('Invoice', function() {
def('user', function() {
return User.create({ role: 'member' });
});
def('invoice', function() {
return $user.invoices.create({ price: 10, currency: 'USD' });
});
describe('by default', function() {
it('has status "fraud" if amount does not equal to invoice amount', function() {
$invoice.paid(1, 'USD');
expect($invoice.status).to.equal('fraud');
});
});
describe('when user is admin', function() {
def('user', function() {
return User.create({ role: 'admin' });
});
it('has status "paid" if amount does not equal to invoice amount', function() {
$invoice.paid(1, 'USD');
expect($invoice.status).to.equal('paid');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment