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
1. Create a new folder for your project. Name it pie-baker
2. Inside the pie-backer folder create two subfolders: src and test
3. Inside the test folder, create a file named pie.spec.js
4. 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(1). a. The essential ingredients are: flour, sugar, and butter.
5. In the pie.spec.js file, you will write unit tests for the bakePie function. You should write at least three tests.
6. In your package.json file, add a test script that runs jest.
7. 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 plant-checker program.
Use toBe or toEqual for your assertions.
Remember to call your functions in each test with the necessary arguments.
Use npm install --save-dev 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 1(condition that does not call process.exit), unit test 2(condition that does not call process.exit), unit test 3(condition that does call process.exit).```
Js pie.js
src > JS pie.js >...
1\**
Author:
* Date:
* File Name:
* Description:
*/
"use strict";
function bakePie(pieType, ingredients){
|// Your code here
}
mogdule.exports ={ bakePie };
``````
test > JS pie.spec.js >...
1/**
* Author:
* Date:
* File Name:
* Description:
*/
"use strict";
const { bakePie }= r...quire("../src/pie");
// Your tests here
``````
Js pie.js
{} package.json \
{} package.json >...
1{
"name": "pie-baker",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
\ Debug
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
```
In this assignment, you will create a module that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!