Question: In this assignment, you will create a module that simulates a simple pie baker. You will use TDD principles and Jest for unit testing. Instructions
In this assignment, you will create a module that simulates a simple pie baker. You will use TDD principles and Jest for unit testing. Instructions
Create a new folder for your project. Name it piebaker
Inside the piebacker folder create two subfolders: src and test
Inside the test folder, create a file named pie.spec.js
In the pie.js file, you will write a function named bakePie that takes a type of pie and an array of ingredients. The function should return a message indicating whether the pie was successfully baked or not. If an essential ingredient is missing, the function should log a warning message and call process.exit a The essential ingredients are: flour, sugar, and butter.
In the pie.spec.js file, you will write unit tests for the bakePie function. You should write at least three tests.
In your package.json file, add a test script that runs jest.
Use TDD principles to guide your development process. Write your tests first, then write the code to make the tests pass, then refactor Red Green Refactor
Hints
Remember to use module.exports to export your function from pie.js and require to import it into pie.spec.js
Use jest.fn to create mock functions in your tests. Follow the format used in the plantchecker program.
Use toBe or toEqual for your assertions.
Remember to call your functions in each test with the necessary arguments.
Use npm install savedev to install jest.
Use npm test to run your tests.
If you are testing a function that calls process.exit, be aware that this will terminate the Node.js process immediately. This means, that any unit tests following a check to process.exit will not be executed and will fail. Structure your unit tests in a way that the test to check process.exit is the last one in the test suite list. For example, unit test condition that does not call process.exit unit test condition that does not call process.exit unit test condition that does call process.exit
Js pie.js
src JS pie.js
Author:
Date:
File Name:
Description:
"use strict";
function bakePiepieType ingredients
Your code here
mogdule.exports bakePie ;
test JS pie.spec.js
Author:
Date:
File Name:
Description:
"use strict";
const bakePie rquiresrcpie;
Your tests here
Js pie.js
package.json
package.json
"name": "piebaker",
"version":
"description":
"main": "index.js
"directories":
"test": "test"
Debug
"scripts":
"test": "echo Error: no test specified && exit
"keywords":
"author":
"license": "ISC"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
