Как мы можем утверждать, что переменная javascript, встроенная в HTML, имеет некоторое ожидаемое значение в приложении, созданном с помощью электронов? Текущая среда тестирования - это spectron, mocha, chai, chai.should () и chai.use (chaiAsPromised).
Я хочу заявить, что глобальная переменная foo
имеет значение 'foo'
. Когда я пытаюсь foo.should.equal('foo')
, я получаю ReferenceError: foo is not defined at Context.<anonymous> (test\spec.js:63:28)
Ниже представлен переработанный spec.js.
const Application = require('spectron').Application
const assert = require('assert')
const electronPath = require('electron') // Require Electron from the binaries included in node_modules.
const path = require('path')
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const should = require('chai').should();
describe('Isolated testbeds house independent suites of tests.', function() {
this.timeout(30000);
before(function() {
this.app = new Application({
path: electronPath,
// directory structure:
// |__ myProject
// |__ ...
// |__ main.js
// |__ package.json
// |__ index.html
// |__ ...
// |__ test
// |__ spec.js <- You are here! ~ Well you should be.
args: [path.join(__dirname, '..')]
})
return this.app.start()
});
after(function() {
if (this.app && this.app.isRunning()) {
return this.app.stop()
}
});
/* BELOW IS THE TEST IN QUESTION */
it('should have a given value', function() {
return Promise.resolve(foo).should.eventually.equal('foo'); // HERE IS THE LINE IN QUESTION
});
})