Skip to content

Instantly share code, notes, and snippets.

@FagnerMartinsBrack
Last active December 21, 2016 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FagnerMartinsBrack/4faa92f4e5d01bac7229fb4e61a71637 to your computer and use it in GitHub Desktop.
Save FagnerMartinsBrack/4faa92f4e5d01bac7229fb4e61a71637 to your computer and use it in GitHub Desktop.
(Medium) When Code Duplication In Tests Is Acceptable - Cart Test Example With Abstraction
const FakeCloth = {
any: () => {
return Product()
.withSize('XL') // Mandatory
.withColor('black'); // Mandatory
}
};
module('Shirts cart');
test('a valid product can be retrieved from the cart after being added', () => {
const fakeShirt = FakeCloth.any().asType('shirt');
const cart = ShirtsCart();
cart.addProduct(fakeShirt);
expect(cart).toContain(fakeShirt);
});
test('when we try to add an invalid product to the cart then it\'s not added', () => {
const fakePants = FakeCloth.any().asType('pants');
const cart = ShirtsCart();
cart.addProduct(fakePants);
expect(cart).not.toContain(fakePants);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment