Почему не хочет запускаться тест Jest?
const getAge = require('./mainScripts');
const { test } = require('picomatch');
const { expect } = require('@jest/globals');
test (
'Проверяем функцию getAge на тип данных',
() => {
expect(getAge(typeof (`${this.firstName}'s old is ${this.age} years`)).toBe('string'));
}
)
Мой код:
class Student {
constructor(firstName,lastName,yearOfBirth,arrayOfGrades) {
this.firstName = firstName;
this.lastName = lastName;
this.yearOfBirth = yearOfBirth;
this.arrayOfGrades = arrayOfGrades;
this.age = new Date().getFullYear() - this.yearOfBirth;
this.avgMark = arrayOfGrades.reduce((sum,item) => {
return sum += item
}, 0) / arrayOfGrades.length;
}
//______Возраст студента______//
getAge () {
return (`${this.firstName}'s old is ${this.age} years`);
}
//______Средний бал______//
averageMark () {
return(`${this.firstName}'s average mark is ${this.avgMark}`);
}
}
class Visit extends Student {
constructor(firstName, lastName, yearOfBirth, arrayOfGrades) {
super(firstName, lastName, yearOfBirth, arrayOfGrades);
this.visitinMagazine = [];
}
//______Используется когда студент был на занятие______//
present () {
if (this.visitinMagazine.length < 26) {
this.visitinMagazine.push(true);
return this;
} else {
return this.visitinMagazine.pop();
}
}
//______Используется когда студент НЕ был на занятие______//
absent () {
if (this.visitinMagazine.length < 26) {
this.visitinMagazine.push(false);
return this;
} else {
return this.visitinMagazine.pop();
}
}
}
class Calculation extends Visit {
constructor(firstName, lastName, yearsOfBirth, arrayOfGrades) {
super(firstName, lastName, yearsOfBirth, arrayOfGrades);
}
//______Проверяем среднюю оценку и посейщение______//
summary () {
const averageVisit = this.visitinMagazine.filter((element) => element === true).length / this.visitinMagazine.length;
if (this.avgMark > 90 && averageVisit > 0.9) {
return console.log('Cool!');
} else if (this.avgMark > 90 || averageVisit > 0.9) {
return console.log('Good, but it can be better!');
} else {
return console.log('Radish');
}
}
}
//______Экземпляры расчетов______//
const calculate = new Calculation('Dmitriy', 'Yaroshchuk', 2001, [70, 80, 90, 100, 90, 90, 99, 100, 95, 100]);
const calculate1 = new Calculation('Andrew', 'Kavetsky', 2000, [90, 90, 90, 90, 90, 90, 100, 100, 95, 93]);
const calculate2 = new Calculation('Diana', 'Koko', 1999, [70, 70, 70, 70, 70, 70, 75, 75, 75, 93]);
console.log(calculate.getAge());
console.log(calculate1.getAge());
console.log(calculate2.getAge());
console.log(calculate.averageMark());
console.log(calculate1.averageMark());
console.log(calculate2.averageMark());
//______Посейщение уроков______//
calculate.present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().absent().absent();
//______Посейщение уроков______//
calculate1.absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().absent().present().present();
//______Посейщение уроков______//
calculate2.present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().present().absent().absent().absent().absent().absent();
calculate.summary();
calculate1.summary();
calculate2.summary();
module.exports = this.getAge;
// module.exports = this.averageMark();
// module.exports = this.present();
// module.exports = this.absent();
Источник: Stack Overflow на русском