首页 > 解决方案 > 为什么茉莉花不运行测试?

问题描述

我刚刚开始学习 jasmine 来测试 JavaScript,对于我的生活,我无法弄清楚为什么 Jasmine 会运行我的布尔测试而不是我的数学函数测试。注意,我使用 index.html 来运行测试,我没有 specrunner.html,尽管我确实有 jasmine 依赖项。这个答案必须很简单。我显然错过了一些东西。

Jasmine 结果- 2 个规范中的 1 个 - 运行所有 1 个规范,0 次失败,随机使用种子 86651

function getOpposite(bool) {
            return !bool; 
        }

        function add(x, y) {
            return x + y;
        }

        describe('math function, addition', () => {
            it('return sum of 2 numbers', () => { //this does not work

                const num1 = 2;
                const num2 = 3;

                const result = add(num1, num2);

                expect(result).toBe(5);
            })
        });

        describe('boolean test', () => {
            it('expect value of true', () => { // this works
               
                let bool = false;

                
                const result = getOpposite(bool);

              
                expect(result).toBe(true);
            })
        });

标签: javascriptunit-testingjasminetdd

解决方案


推荐阅读