Skip to content

Instantly share code, notes, and snippets.

@goldbergyoni
Created December 20, 2018 23:43
Show Gist options
  • Select an option

  • Save goldbergyoni/a07f88922d5f5063f4be31877334e422 to your computer and use it in GitHub Desktop.

Select an option

Save goldbergyoni/a07f88922d5f5063f4be31877334e422 to your computer and use it in GitHub Desktop.
Testing whitebox
class ProductService{
//this method is only used internally
//Change this name will make the tests fail
calculateVAT(priceWithoutVAT){
return {finalPrice: priceWithoutVAT * 1.2};
//Change the result format or key name above will make the tests fail
}
//public method
getPrice(productId){
const desiredProduct= DB.getProduct(productId);
finalPrice = this.calculateVATAdd(desiredProduct.price).finalPrice;
}
}
it("White-box test: When the internal methods get 0 vat, it return 0 response", async () => {
//There's no requirement to allow users to calculate the VAT, only show the final price. Nevertheless we falsely insist here to test the class internals
expect(new ProductService().calculateVATAdd(0).finalPrice).to.equal(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment