Hi all I am trying to test the below code using Jest however I am receiving an error of mData not defined when I am running the test.
(大家好,我正在尝试使用Jest测试下面的代码,但是我在运行测试时收到未定义的mData错误。)
Please take a look at the code below and if possible please let me know where I am going wrong here.(请查看下面的代码,如果可能的话,请让我知道我在哪里出错。)
Thanks in advance.(提前致谢。)
function createMilkShakeData(mData) {
}
describe("milkshake Data Generator", () => {
it("creates correct data structure ", () => {
const mData = [
"milkshake1/milkshake1flavour",
"milkshake1/milkshake1flavor2",
"milkshake2/milkshake2flavour",
"milkshake2/milkshake2flavour2",
"milkshake1/milkshake1flavour3",
"flavour3",
"milkshake3/flavour3flavour1",
"milkshake4"
];
const expectedResult = [
{
title: "milkshake1",
data: ["milkshake1flavour", "milkshake1flavour2", "milkshake1flavour3"]
},
{ title: "milkshake2", data: ["milkshake2flavour", "milkshake2flavour2"] },
{ title: "milkshake3", data: ["milkshake3flavour1"] }
];
const actualResult = createMilkShakeData(mData);
expect(actualResult).toMatchObject(expectedResult);
});
});
module.exports = createMilkShakeData
module.exports = mData
code from test file below
(下面测试文件中的代码)
const createMilkShakeData = require('./milkshake')
const data = require('./milkshake')
test('milkshake Data Generator', () => {
const actualResult = createMilkShakeData(mData);
expect(actualResult).toMatchObject(expectedResult)}
)
ask by Billy Atim translate from so