Мокко неопределенные тесты и странное поведение - PullRequest
0 голосов
/ 20 марта 2019

Проблема в том, что mocha выводит неверные данные

вывод теста mocha / test

PS C: \ Users \ rluth \ API \ main \ test> mocha

kordata API
    matching given hufflepuff and gryffindor
      1) should be false
    matching given gryffindor and gryffindor
      2) should be true
    values of grades
      3) given A it should be 4
    values of grades
      4) given F it should be 0


  0 passing (17ms)
  4 failing

  1) kordata API
       matching given hufflepuff and gryffindor
         should be false:
     TypeError: scripts.matchingClass is not a function
      at Object.matchShouldFail (src\testscripts.js:7:24)
      at Context.it (test\test.js:7:42)

  2) kordata API
       matching given gryffindor and gryffindor
         should be true:
     TypeError: scripts.matchingClass is not a function
      at Object.matchShouldPass (src\testscripts.js:11:24)
      at Context.it (test\test.js:11:41)

  3) kordata API
       values of grades
         given A it should be 4:
     TypeError: test.AShouldBe4 is not a function
      at Context.it (test\test.js:15:49)

  4) kordata API
       values of grades
         given F it should be 0:
     TypeError: test.FShouldBe0 is not a function
      at Context.it (test\test.js:19:49)

Вот тест / src / testscripts.js

'use strict';
const expect = require("chai").expect
var scripts = require("../../Resources/js/functions.js")

module.exports = {
    matchShouldFail: function() {
        expect(scripts.matchingClass("hufflepuff","gryffindor").to.equal(false))
    },

    matchShouldPass: function() {
        expect(scripts.matchingClass("gryffindor","gryffindor").to.equal(true))
    },

    AshouldBe4: function() {
        expect(scripts.calculateGradePoint("A").to.equal(4))
    },

    FshouldBe0: function() {
        expect(scripts.calculateGradePoint("F").to.equal(0))
    },

    shouldBe3: function() {
        expect(scripts.roundToHundreth(3,1,1).to,equal(3))
    },

    shouldBe2_25: function() {
        expect(scripts.roundToHundreth(18,4,2).to.equal(2.25))
    },

    classShouldBe1: function() {
        student = ["gym"]
        expect(scripts.countClasses(student).to.equal(1))
    },

    classShouldBe3: function() {
        student = ["gym", "english", "potions"]
        expect(scripts.countClasses(student.to.equal(3)))
    }
};

Как вы можете видеть, я получаю этот странный вывод, когда его половину моих переменных переименовывают в test.functionname, а другая половина остается прежней.Также я чувствую, что мой код для моих тестов отлично работает

/ main / resources / js / functions / js

module.exports = {

    CalculateGradePoint: function (letterGrade) {
        if (letterGrade === "A")
            return 4

        if (letterGrade === "B")
            return 3

        if (letterGrade === "C")
            return 2

        if (letterGrade === "D")
            return 1

        if (letterGrade === "E")
            return 0
    },

    //checks if two values are the same
    matching: function (actual, expected) {
        if (actual === expected)
            return true
        return false
    },

    //calculates a GPA value to the nearest hundreth depeding
    //on amount of students and classes and each students grade from that class
    roundToHundreth: function (GPA, students, totalClasses) {
        return Math.round(100 * GPA / (students * totalClasses)) / 100
    },

    //counts the amount of classes a student is taking
    countClasses: function (student) {
        var count = 0,
            loop = 0
        len = student.courses.length
        for (loop = 0; loop < len; loop++)
            count++
    }
};

и файл, который вызывает их

main/test/src/testscripts.js

'use strict';
const expect = require("chai").expect
var scripts = require("../../Resources/js/functions.js")

module.exports = {
    matchShouldFail: function() {
        expect(scripts.matchingClass("hufflepuff","gryffindor").to.equal(false))
    },

    matchShouldPass: function() {
        expect(scripts.matchingClass("gryffindor","gryffindor").to.equal(true))
    },

    AshouldBe4: function() {
        expect(scripts.calculateGradePoint("A").to.equal(4))
    },

    FshouldBe0: function() {
        expect(scripts.calculateGradePoint("F").to.equal(0))
    },

    shouldBe3: function() {
        expect(scripts.roundToHundreth(3,1,1).to,equal(3))
    },

    shouldBe2_25: function() {
        expect(scripts.roundToHundreth(18,4,2).to.equal(2.25))
    },

    classShouldBe1: function() {
        student = ["gym"]
        expect(scripts.countClasses(student).to.equal(1))
    },

    classShouldBe3: function() {
        student = ["gym", "english", "potions"]
        expect(scripts.countClasses(student.to.equal(3)))
    }
};

Я пытался искать другие проблемы, но они обычно были вызваны тем, что функции вообще не импортировались или просто неправильно.И что я действительно не понимаю, так это то, почему половина имен тестов имеет старое имя переменной, а остальные - новые.Главным образом, почему мой код не работает.Я чувствую, что все настроено правильно.У меня были проблемы с отсутствием функций, но я понял, как с этим справиться.И теперь мне говорят, что эти функции не являются функцией.Я предполагаю, что это небольшая вещь, так как я впервые использую этот материал самостоятельно.Любая помощь приветствуется.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...