电子,内部封装和测试

时间:2016-05-19 11:15:17

标签: javascript electron

我实际上正在使用电子构建一个应用程序,而且我遇到了处理电子内置包的麻烦。

我有一个测试,看起来像使用chai mocha an:

it('should call the remote#hideWindow method', () => {

            /**
             * Mock definition
             */
            mock.expects('getCurrentWindow').returns({
                hide: () => {
                    // Do some job
                }
            });

            const spy = chai.spy(remote.getCurrentWindow().hide);

            /**
             * Real test case
             */
            const googleSearchBar = new GoogleSearchBar(document.getElementById('search'));
            googleSearchBar.hideWindow();
            expect(spy).to.have.been.called();
        });

我的问题是我无法使用遥控器'包使用:

const remote = require('remote');

事实上,我可以要求('远程')在我的应用内部,一个在浏览器上运行,但不在我的测试中。而且我不知道如何在我的测试文件中访问它。

你能帮助我吗?

编辑:当我尝试使用Web API(例如通知或webspeechrecognition)时,会发生同样的事情。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您没有指定实际运行这些测试的方式,它们必须在电子流程中运行,而不是在常规节点流程中运行。我建议查看Spectron