Created
December 5, 2017 22:16
-
-
Save intojs/59a1eaa0f99110dd87ea41ef97a2048e to your computer and use it in GitHub Desktop.
Mocking in Typescript - product-utils.spec
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
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