This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sharedExampleFor('Range validator', function(fieldName, min, max) { | |
it('rejects values greater than "max" value', function() { | |
$subject[fieldName] = max() + 1; | |
expect($subject.hasErrorOn(fieldName)).to.be.true; | |
}); | |
it('rejects values less than "min" value', function() { | |
$subject[fieldName] = min() - 1; | |
expect($subject.hasErrorOn(fieldName)).to.be.true; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function itBehavesLike(type) { | |
var args = arguments; | |
describe('behaves like "' + type + '"', function() { | |
includeExamplesFor.apply(this, args); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Array', function() { | |
subject(function() { | |
return []; | |
}); | |
includeExamplesFor('Collection'); | |
}); | |
describe('Set', function() { | |
subject(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sharedExamplesFor('Collection', function() { | |
it('is empty by default', function() { | |
expect($subject).to.be.empty; | |
}); | |
it('increments "length" property when adds a new item', function() { | |
$subject.add(1, 2, 3); | |
expect($subject).to.have.length(3); | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Article', function() { | |
subject(function() { | |
return Article.create({ title: 'BDD lazy vars' }); | |
}); | |
its('status', () => is.expected.to.equal('draft')); | |
describe('changes history', function() { | |
subject(function() { | |
return $subject.changes(); // $subject refers to parent subject, i.e. created article |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Article', function() { | |
subject(function() { | |
return Article.create({ title: 'BDD lazy vars' }); | |
}); | |
its('status', () => is.expected.to.equal('draft')); | |
// or even better | |
it(() => is.expected.to.be.a.draft); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Article', function() { | |
subject(function() { | |
return Article.create({ title: 'BDD lazy vars' }); | |
}); | |
it('is created as a draft by default', function() { | |
expect($subject.status).to.equal('draft'); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Article', function() { | |
def('article', function() { | |
return new Article({ type: 'news', }); | |
}); | |
before(function() { | |
article.id = 1; // first instance | |
}); | |
before(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe('Invoice', function() { | |
var invoice, user; | |
describe('by default', function() { | |
beforeEach(function() { | |
user = User.create({ role: 'member' }); | |
invoice = user.invoices.create({ price: 10, currency: 'USD' }); | |
}); | |
it('has status "fraud" if amount does not equal to invoice amount', function() { |