摩卡咖啡未定义的测试和奇怪的行为

时间:2019-03-20 03:41:41

标签: node.js mocha

问题是摩卡咖啡输出的数据不正确

mocha测试/测试的输出

PS C:\ Users \ rluth \ API \ main \ test>摩卡

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)

这里是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)))
    }
};

如您所见,我得到了这个奇怪的输出,其中将其重命名的一半变量重命名为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)))
    }
};

我曾经尝试过寻找其他问题,但是这些问题通常是由于根本没有导入功能或只是错误地导致的。我真正不明白的是,为什么一半的测试名称具有旧的变量名称,而另一半具有新的变量名称。主要是为什么我的代码无法正常工作。我觉得一切设置正确。我确实没有找到功能,但是想出了解决方法。现在,我被告知这些功能不是功能。我认为这是一件小事,因为这是我第一次自己使用这些东西。任何帮助表示赞赏。

0 个答案:

没有答案
相关问题