首页 文章

为什么这些柴测试不会失败?

提问于
浏览
1

我们有一些简单的“这是真的有效”的电子应用程序的chai测试使用spectron和WebdriverIO . 我们开始的示例代码来自

https://github.com/jwood803/ElectronSpectronDemohttps://github.com/jwood803/ElectronSpectronDemo/issues/2中报道的那样,chai-as-promised测试没有捕捉不匹配,所以我想我会添加一些额外的测试来找出为什么Chai没有失败测试,其中电子应用程序的文本与预期的单位不匹配测试文本 .

让我们从一些非常简单的东西开始,代码的其余部分位于https://github.com/drjasonharrison/ElectronSpectronDemo

describe('Test Example', function () {
    beforeEach(function (done) {
        app.start().then(function() { done(); } );
    });

    afterEach(function (done) {
        app.stop().then(function() { done(); });
    });

    it('yes == no should fail', function () {
        chai.expect("yes").to.equal("no");
    });

    it('yes == yes should succeed', function () {
        chai.expect("yes").to.equal("yes");
    });

第一次单元测试失败,第二次单元测试成功 .

当我们将断言放入函数时,仍会检测到失败:

it('should fail, but succeeds!?', function () {
    function fn() {
        var yes = 'yes';
        yes.should.equal('no');
    };
    fn();
});

所以现在进入电子,webdriverio和光谱的世界,应用程序 Headers 应该是“Hello World!”,所以这应该失败,但它通过:

it('tests the page title', function () {
    page.getApplicationTitle().should.eventually.equal("NO WAY");
});

嗯,让我们尝试更熟悉的测试:

it('should fail, waitUntilWindowLoaded, yes != no', function () {
    app.client.waitUntilWindowLoaded().getTitle().then(
        function (txt) {
            console.log('txt = ' + txt);
            var yes = 'yes';
            yes.should.equal('no');
        }
    );
});

输出:

✓ should fail, waitUntilWindowLoaded, yes != no
txt = Hello World!

它成功了吗?什么?为什么?怎么样?

1 回答

相关问题