Skip to content

Instantly share code, notes, and snippets.

@intojs
Created December 5, 2017 22:16
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 intojs/59a1eaa0f99110dd87ea41ef97a2048e to your computer and use it in GitHub Desktop.
Save intojs/59a1eaa0f99110dd87ea41ef97a2048e to your computer and use it in GitHub Desktop.
Mocking in Typescript - product-utils.spec
import { Product } from './Product';
import { Price } from './Price';
import { filterProductsByName, addPriceToProduct } from './product-utils';
describe('product-utils', () => {
test('filterProductsByName', () => {
const name = 'Puffy';
const puffy: Product = {
name: 'Puffy',
description: 'the description',
longDescription: 'the long description',
imageOne: 'imageOne src',
imageTwo: 'imageTwo src',
imageThree: 'imageThree src',
price: null // We do not need a price, keeping it null
};
const fluffy: Product = {
name: 'Flully',
description: 'the description',
longDescription: 'the long description',
imageOne: 'imageOne src',
imageTwo: 'imageTwo src',
imageThree: 'imageThree src',
price: null // We do not need a price, keeping it null
};
const products: Product[] = [puffy, fluffy];
expect(filterProductsByName('Puffy')(products)).toEqual([puffy]);
});
test('addPriceToProduct', () => {
const product: Product = {
name: 'Flully',
description: 'the description',
longDescription: 'the long description',
imageOne: 'imageOne src',
imageTwo: 'imageTwo src',
imageThree: 'imageThree src',
price: null // We do not need a price, keeping it null
};
const price: Price = {
value: 1000,
currency: 'EUR',
vat: 190,
stringRepresentation: '1190 €'
};
const productWithPrice: Product = {
name: 'Flully',
description: 'the description',
longDescription: 'the long description',
imageOne: 'imageOne src',
imageTwo: 'imageTwo src',
imageThree: 'imageThree src',
price: {
value: 1000,
currency: 'EUR',
vat: 190,
stringRepresentation: '1190 €'
}
};
expect(addPriceToProduct(price)(product)).toEqual(productWithPrice);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment