This file contains hidden or 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
| {"lastUpload":"2018-09-23T09:34:34.812Z","extensionVersion":"v3.1.2"} |
This file contains hidden or 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
| const EventEmitter = require("events"); | |
| class Session extends EventEmitter { | |
| constructor(id) { | |
| super(); | |
| this.id = id; | |
| } | |
| start() { | |
| console.log(`Session is about to start ${this.id}`); |
This file contains hidden or 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
| 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); |
This file contains hidden or 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("Too short description", () => { | |
| const userToken = userService.getDefaultToken() // *error:no-setup-in-describe, use hooks (sparingly) instead | |
| it("Some description", () => {});//* error: valid-test-description. Must include the word "Should" + at least 5 words | |
| }); | |
| it.skip("Test name", () => {// *error:no-skipped-tests, error:error:no-global-tests. Put tests only under describe or suite | |
| expect("somevalue"); // error:no-assert | |
| }); | |
| it("Test name", () => {*//error:no-identical-title. Assign unique titles to tests |
This file contains hidden or 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
| test("When getting orders report, get the existing orders", () => { | |
| const queryObject = QueryHelpers.getQueryObject(config.DBInstanceURL); | |
| const reportConfiguration = ReportHelpers.getReportConfig();//What report config did we get? have to leave the test and read | |
| userHelpers.prepareQueryPermissions(reportConfiguration);//what this one is doing? have to leave the test and read | |
| const result = queryObject.query(reportConfiguration); | |
| assertThatReportIsValid();//I wonder what this one does, have to leave the test and read | |
| expect(result).to.be.an('array').that.does.include({id:1, productd:2, orderStatus:"approved"}); | |
| //how do we know this order exist? have to leave the test and check | |
| }) |
This file contains hidden or 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
| it("When getting orders report, get the existing orders", () => { | |
| //This one hopefully is telling a direct and explicit story | |
| const orderWeJustAdded = ordersTestHelpers.addRandomNewOrder(); | |
| const queryObject = newQueryObject(config.DBInstanceURL, queryOptions.deep, useCache:false); | |
| const result = queryObject.query(config.adminUserToken, reports.orders, pageSize:200); | |
| expect(result).to.be.an('array').that.does.include(orderWeJustAdded); | |
| }) |
This file contains hidden or 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 addNewOrder(newOrder) { | |
| logger.log(`Adding new order ${newOrder}`); | |
| DB.save(newOrder); | |
| Mailer.sendMail(newOrder.assignee, `A new order was places ${newOrder}`); | |
| return {approved: true}; | |
| } | |
| it("Test addNewOrder, don't use such test names", () => { | |
| addNewOrder({asignee: "John@mailer.com",price: 120}); |
This file contains hidden or 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
| //1. unit under test | |
| describe('Products Service', function() { | |
| describe('Add new product', function() { | |
| //2. scenario and 3. expectation | |
| it('When no price is specified, then the product status is pending approval', ()=> { | |
| const newProduct = new ProductService().add(...); | |
| expect(newProduct.status).to.equal('pendingApproval'); | |
| }); | |
| }); | |
| }); |
This file contains hidden or 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
| it("When a valid product is about to be deleted, ensure data access DAL was called once, with the right product and right config", async () => { | |
| //Assume we already added a product | |
| const dataAccessMock = sinon.mock(DAL); | |
| //hmmm BAD: testing the internals is actually our main goal here, not just a side-effecr | |
| dataAccessMock.expects("deleteProduct").once().withArgs(DBConfig, theProductWeJustAdded, true, false); | |
| new ProductService().deletePrice(theProductWeJustAdded); | |
| mock.verify(); | |
| }); |
This file contains hidden or 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
| it("When a valid product is about to be deleted, ensure an email is sent", async () => { | |
| //Assume we already added here a product | |
| const spy = sinon.spy(Emailer.prototype, "sendEmail"); | |
| new ProductService().deletePrice(theProductWeJustAdded); | |
| //hmmm OK: we deal with internals? Yes, but as a side effect of testing the requirements (sending an email) | |
| }); |
OlderNewer